fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. cin >> n; // Read the number of days
  9. vector<int> a(n); // Create a vector to store money made each day
  10.  
  11. for (int i = 0; i < n; ++i) {
  12. cin >> a[i]; // Read each day's earnings
  13. }
  14.  
  15. int maxLength = 1; // Maximum length of non-decreasing subsegment found
  16. int currentLength = 1; // Length of the current non-decreasing subsegment
  17.  
  18. for (int i = 1; i < n; ++i) {
  19. if (a[i] >= a[i - 1]) {
  20. currentLength++; // Increment current length if non-decreasing
  21. } else {
  22. maxLength = max(maxLength, currentLength); // Update max length if necessary
  23. currentLength = 1; // Reset current length
  24. }
  25. }
  26.  
  27. // Final check for the last segment
  28. maxLength = max(maxLength, currentLength);
  29.  
  30. cout << maxLength << endl; // Output the result
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
5426