Please can anybody help me with my code. I don't get why I'm getting WA. My solution is to find the next permutation of the input number. If the permutation is exactly like the input then return "-1". Thank you.
#include <bits/stdc++.h>
using namespace std;
int t;
long long n, a[1000001];
main() {
scanf("%d", &t);
while(t--) {
string res, cur;
scanf("%lld", &n);
for(int i = 1 ; i <= n ; ++i) {
scanf("%lld", &a[i]);
char c = a[i] + '0';
cur.append(1, c);
}
next_permutation(a + 1, a + n + 1);
//for(int i = 1 ; i <= n ; ++i) {
// cout << a[i] << " ";
//}
//cout << endl;
for(int i = 1 ; i <= n ; ++i) {
char c = a[i] + '0';
res.append(1, c);
}
if(cur == res) cout << "-1\n";
else cout << res << endl;
}
}