fork(2) download
  1. #include <bits/stdc++.h>
  2. #define endl "\n"
  3. using namespace std;
  4. int main()
  5. {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(NULL);
  8. int T,N,tmp;
  9. cin>>T;
  10. for(int z=0; z<T; z++)
  11. {
  12. vector <int> arr;
  13. cin>>N;
  14. for(int i=0; i<N; i++)
  15. {
  16. cin>>tmp;
  17. arr.push_back(tmp);
  18. }
  19. bool x = next_permutation(arr.begin(), arr.end());
  20. if(x)
  21. {
  22. for(int i=0; i<N; i++)
  23. cout<<arr[i];
  24. }
  25. else
  26. cout<<-1;
  27. cout<<endl;
  28.  
  29. }
  30. return 0;
  31. }
Time limit exceeded #stdin #stdout 5s 2100380KB
stdin
Standard input is empty
stdout
Standard output is empty