fork(1) download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long int
  6.  
  7. ll toNumber(ll array[], int N)
  8. {
  9. for(int i = 0; i < N; i++)
  10. cout<<array[i];
  11. }
  12.  
  13. void print_vector(vector<ll> array)
  14. {
  15. for(int i = 0, n = array.size(); i < n; i++)
  16. cout<<array[i]<<" ";
  17. cout<<endl;
  18. }
  19.  
  20. int main()
  21. {
  22. int t = 0;
  23. cin>>t;
  24.  
  25. while(t--)
  26. {
  27. int N = 0;
  28. cin>>N;
  29.  
  30. ll array[N];
  31.  
  32. for(int i = 0; i < N; i++)
  33. cin>>array[i];
  34.  
  35. if(next_permutation(array,array+N))
  36. cout<<toNumber(array,N)<<endl;
  37. else
  38. cout<<-1<<endl;
  39. }
  40. }
Success #stdin #stdout 0s 4276KB
stdin
Standard input is empty
stdout
Standard output is empty