fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void print_vector(vector<int> array)
  6. {
  7. for(int i = 0, n = array.size(); i < n; i++)
  8. cout<<array[i]<<" ";
  9. cout<<endl;
  10. }
  11.  
  12. int main()
  13. {
  14. int n = 0;
  15. while(cin>>n)
  16. {
  17. if(n == 0)break;
  18.  
  19. vector<int> array(n);
  20. stack<int> s1,s2;
  21. for(int i = 0; i < n; i++)
  22. cin>>array[i];
  23.  
  24. for(int i = 0; i < n - 1; i++)
  25. {
  26. if(array[i] > array[i+1])
  27. {
  28. s1.push(array[i]);
  29. }
  30. else if(!s1.empty())
  31. {
  32. if(array[i+1]>s1.top())
  33. {
  34. s2.push(s1.top());
  35. s1.pop();
  36. }
  37.  
  38. else
  39. s2.push(array[i]);
  40. }
  41. else
  42. s2.push(array[i]);
  43. }
  44. s2.push(array[n-1]);
  45. while(!s1.empty())
  46. {
  47. s2.push(s1.top());
  48. s1.pop();
  49. }
  50. bool flag = true;
  51. int x = s2.top();
  52. s2.pop();
  53. while(!s2.empty())
  54. {
  55. if(x < s2.top())
  56. {
  57. flag = false;
  58. }
  59. x=s2.top();
  60. s2.pop();
  61. }
  62. if(flag)
  63. cout<<"yes\n";
  64. else
  65. cout<<"no\n";
  66. }
  67. }
Success #stdin #stdout 0s 4392KB
stdin
Standard input is empty
stdout
Standard output is empty