I came across this problem, and i am having a little difficulty in solving the problem, can anyone help me where i am going wrong ?
My solution: I know this should give TLE but why is it giving wrong answer lol
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool check(vector <int> &a, vector<int> &b) {
set <int> s;
for(int i=0;i<a.size();i++) {
s.insert(a[i]+b[i]);
}
return (a.size() == s.size());
}
int main(){
ios::sync_with_stdio(false); cin.tie(NULL);
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
vector <int> a(n),b(n);
for(int i=0;i<n;i++) {
cin >> a[i];
}
for(int i=0;i<n;i++) {
cin >> b[i];
}
bool exists =check(a,b);
while(!exists) {
random_shuffle(begin(a),end(a));
exists = check(a,b);
}
for(int i=0;i<n;i++) {
cout << a[i] << " ";
}
cout << '\n';
for(int i=0;i<n;i++) {
cout << b[i] << " ";
}
cout << '\n';
}
}