Ankit_132

B

Jan 3rd, 2024
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int t;
  7.     cin>>t;
  8.    
  9.     while(t--)
  10.     {    
  11.         int n;
  12.         cin >> n;
  13.         int a[n], b[n];
  14.         for(int i = 0; i < n; i++) {
  15.             cin >> a[i];
  16.         }
  17.         for(int i = 0; i < n; i++) {
  18.             cin >> b[i];
  19.         }
  20.        
  21.         sort(a, a+n);
  22.         sort(b, b+n, greater<int>());
  23.        
  24.         int prev = a[0] + b[0], f=1;
  25.         for(int i = 1; i < n && f; i++) {
  26.             if(prev != a[i] + b[i]) {
  27.                 cout << -1 << endl;
  28.                 f=0;
  29.             }
  30.         }
  31.         for(int i = 0; i < n && f; i++) {
  32.             cout << a[i] << " ";
  33.         }
  34.         cout << endl;
  35.         for(int i = 0; i < n && f; i++) {
  36.             cout << b[i] << " ";
  37.         }
  38.         cout << endl;
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment