fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pi pair<int,int>
  4. bool cmp(pi a,pi b)
  5. {
  6. return a.first>b.first;
  7. }
  8. int main()
  9. {
  10. int n;cin>>n;
  11. int a[n],b[n];
  12. for(int i=0;i<n;i++)cin>>a[i];
  13. for(int i=0;i<n;i++)cin>>b[i];
  14. vector<pair<int,int>>adj;
  15. for(int i=0;i<n;i++)
  16. {
  17. adj.push_back({a[i],b[i]});
  18.  
  19. }
  20. sort(adj.begin(),adj.end(),cmp);
  21. for(int i=0;i<n;i++)
  22. {
  23. cout<<adj[i].first<<" "<<" ";
  24.  
  25. }
  26. for(int i=0;i<n;i++)
  27. {
  28. cout<<adj[i].second<<" ";
  29.  
  30. }
  31. }
Success #stdin #stdout 0s 4548KB
stdin
5
10 8 7 1 2 
2 3 4 1 6
stdout
10  8  7  2  1  2 3 4 6 1