fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. pair <int,int> a[1000000];
  4. int arr1[1000000],arr2[100000];
  5. int main()
  6. {
  7. int n,i;
  8. scanf("%d",&n);
  9. for(i=0;i<n;i++) scanf("%d",&arr1[i]); //First row
  10. for(i=0;i<n;i++) scanf("%d",&arr2[i]); //Second row
  11. for(i=0;i<n;i++)
  12. {
  13. a[i]=make_pair(arr1[i],arr2[i]);
  14. }
  15. sort(a,a+n); //Sorts according to first row
  16. printf("\n");
  17. for(i=0;i<n;i++) printf("%d ",a[i].first);
  18. printf("\n");
  19. for(i=0;i<n;i++) printf("%d ",a[i].second);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 15568KB
stdin
6

6 4 8 7 3

4 9 5 1 0 2
stdout
3 4 4 6 7 8 
2 0 5 9 0 1