fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int N;
  6. int H[100000];
  7. int ms = 0, me, mns;
  8. int maxwidth = 0;
  9.  
  10. int main(){
  11.  
  12. cin >> N;
  13. for (int i = 0; i < N; i++)
  14. cin >> H[i];
  15.  
  16. int i = 0;
  17. while (i < N){
  18. int dH = H[i+1] - H[i];
  19. while (dH >= 0 && i < N){
  20. i++;
  21. dH = H[i+1] - H[i];
  22. }
  23. //reached peak
  24. while (dH <= 0 && i < N){
  25. if (dH < 0)
  26. mns = i+1;
  27. i++;
  28. dH = H[i+1] - H[i];
  29. }
  30. if (i == N){
  31. maxwidth = max(maxwidth, i-ms);
  32. //cout << "mountain from " << ms << " to " << i-1 << "\n";
  33. }
  34. else{
  35. maxwidth = max(maxwidth, i-ms+1);
  36. //cout << "mountain from " << ms << " to " << i << "\n";
  37. }
  38. ms = mns;
  39. //reached start of next peak
  40. }
  41.  
  42. cout << maxwidth << "\n";
  43.  
  44. }
  45.  
Success #stdin #stdout 0s 15624KB
stdin
7
3
2
3
5
4
1
6
stdout
5