fork download
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9. int a[10],b,c,x,n,mcoun,i;
  10. vector <int> store,index,coun;
  11.  
  12.  
  13. cin>>n;
  14.  
  15. for(i=0;i<n;i++)
  16. {
  17. cin>>a[i];
  18. }
  19. x=0;
  20. i=0;
  21. c=0;
  22. do{
  23. b=a[0];
  24. c=0;
  25. for(;i<n;i++)
  26. {
  27.  
  28. if(b<a[i])
  29. {
  30. c++;
  31. b=a[i];
  32. }
  33. else
  34. {
  35. store.push_back(a[i]);
  36. index.push_back(i);
  37. }
  38. }
  39. coun.push_back(c);
  40.  
  41. a[i]=store.at(x);
  42. i=index.at(x);
  43. x++;
  44. store.erase(store.begin()+0);
  45. index.erase(index.begin()+0);
  46. }while(store.size()>0);
  47. mcoun=coun[0];
  48. for(i=1;i<coun.size();i++)
  49. {
  50. mcoun=max(mcoun,coun[i]);
  51. }
  52. cout<<mcoun<<endl;
  53.  
  54.  
  55. return 0;
  56. }
  57.  
Runtime error #stdin #stdout #stderr 0s 3276KB
stdin
5
1 4 2 4 3
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 8) >= this->size() (which is 7)