Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void merge(vector<int> &v,int left,int right)
- {
- int mid=(left+right)/2;
- int p1=left,p2=mid+1,k=0;
- vector<int> temp(right-left+1);
- while(p1<mid+1&&p2<right+1)
- {
- if(v[p1]<v[p2])
- temp[k++]=v[p1++];
- else
- temp[k++]=v[p2++];
- }
- while(p1<mid+1)
- temp[k++]=v[p1++];
- while(p2<right+1)
- temp[k++]=v[p2++];
- k=0;
- for(int i=left;i<=right;i++)
- v[i]=temp[k++];
- }
- void MS(vector<int> &v,int left,int right)
- {
- if(left==right)
- return;
- int mid=(left+right)/2;
- MS(v,left,mid);//left half sorting
- MS(v,mid+1,right);//right half sorting
- merge(v,left,right);//merging the two sorted parts
- /* for(auto x:v)
- cout<<x;
- cout<<endl;*/
- }
- int main()
- {
- int tc;
- cin>>tc;
- vector<int> c(tc);
- vector<vector<int>> z;
- for(int i=0;i<tc;i++)
- {
- cin>>c[i];
- vector<int> v(c[i]);
- for(int j=0;j<c[i];j++)
- {
- int temp;
- cin>>temp;
- v[j]+=temp;
- }
- MS(v,0,c[i]-1);
- /* for(auto x:v)
- {
- cout<<x<<" ";
- }cout<<endl;*/
- z.push_back(v);
- }
- for(int i=0;i<tc;i++)
- {
- set<int> s;
- vector<int> v=z[i];
- for(int j=0;j<c[i];j++)
- {
- cout<<v[j]<<" ";
- if(v[j]==v[j-1])
- s.insert(v[j]);
- }cout<<endl;
- /* for(auto x:s)
- cout<<x<<" ";
- cout<<endl;*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement