fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int N;
  6.  
  7. cin >> N;
  8.  
  9. vector<int> A(N);
  10. vector<int> B(N,1000);
  11.  
  12. bool answer = false;
  13.  
  14.  
  15. for(int i=0; i<N; i++){
  16. cin >> A.at(i);
  17. }
  18.  
  19.  
  20. for(int i=0; i<N; i++){
  21. for(int k=0; k<N; k++){
  22. B.at(k) = 1000;
  23. }
  24. for(int j=0; j<i; j++){
  25. if(A.at(j)>A.at(i)){
  26. B.at(j) = A.at(j);
  27. answer = true;
  28. }
  29. }
  30. if(answer){
  31. int min = B.at(0);
  32. for(int i=1; i<N; i++){
  33. if(min > B.at(i)){
  34. min = B.at(i);
  35. }
  36. }
  37. cout << min << endl;;
  38. }else{
  39. cout << -1 << endl;
  40. }
  41. }
  42. // your code goes here
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5324KB
stdin
4
4 3 2 5
stdout
-1
4
3
1000