Codeforces Round 874 (Div. 3) 1833B - Restore the Weather Solution


 

Problem Link : https://codeforces.com/contest/1833/problem/B

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. const int N = 1e5+9 ;
  5. pair<int,int>a[N],b[N];
  6. int ans[N] ;
  7. int32_t main() {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. int t;
  11. cin >> t;
  12. while (t--) {
  13. int n , k ;
  14. cin >> n >> k ;
  15. for ( int i = 1 ; i <= n ; i++) {
  16. cin >> a[i].first;
  17. a[i].second = i ;
  18. }
  19. for ( int i = 1 ; i <= n ; i++) {
  20. cin >> b[i].first;
  21. b[i].second = i ;
  22. }
  23. sort( a + 1 , a + n + 1) ;
  24. sort( b + 1 , b + n + 1) ;
  25. for ( int i = 1 ; i <= n ; i++) {
  26. ans[a[i].second] = b[i].first ;
  27. }
  28. for ( int i = 1 ; i <= n ; i++) {
  29. cout << ans[i] <<" ";
  30. }
  31. cout <<"\n" ;
  32. }
  33. return 0;
  34. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.