fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool small(int a[],int pos,int num,int n)
  4. {
  5. for(int i=pos;i<n ;i++)
  6. {
  7. if(num>a[pos])
  8. return false;
  9. }
  10. return true;
  11. }
  12.  
  13. int main()
  14. {
  15. int in[1000],fin[1000];
  16. stack <int> s;
  17. int t;
  18. cin>>t;
  19. while(t--)
  20. { int n,x=0;
  21. cin>>n;
  22. for(int i=0;i<n;i++)
  23. {
  24. cin>>in[i];
  25. }
  26. for(int i=0;i<n;i++)
  27. {
  28. if(small(in,i+1,in[i],n))
  29. {
  30. fin[x]=in[i];
  31. x++;
  32. }
  33. else
  34. s.push(in[i]);
  35. }
  36. while(!s.empty())
  37. { //cout<<s.top();
  38. fin[x]=s.top();
  39. s.pop();
  40. x++;
  41. }
  42. int count1=0;
  43. for(int i=x-1;i>0;i--)
  44. {
  45. if(fin[i]<=fin[i-1])
  46. count1++;
  47. }
  48. if(count1==0)
  49. cout<<"Yes";
  50. else
  51. cout<<"No";
  52. }
  53.  
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 15240KB
stdin
3
5
4
3
5
2
1
2
1
2
4
1
2
3
4
stdout
NoYesYes