Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define rep(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++)
#define rrep(i, a, b) for (int(i) = int(a); (i) >= int(b); (i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)1e9 + 1
#define MOD (long long)1e9 + 7
#define INF64 (long long)1e18 + 1

#define F first
#define S second

#define Pii pair<int, int>
#define Pll pair<long long, long long>
#define Piii pair<int, pair<int, int>>
#define Plll pair<long long, pair<long long, long long>>

#define Vll(a, b, c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a, b, c, d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main(void) {
  // INPUT
  llint N;
  cin >> N;
  vector<llint> H(N);
  rep(i, 0, N) {
    llint bufh;
    cin >> H[i];
  }

  // SOLVE
  llint ans = 0;
  llint now;
  llint bufa;
  for (now = 0; now < N; now++) {
    // auto itl = upper_bound(H.begin()+now,H.end(), H[now]);
    // bufa = H.end() - (H.begin()+now);
    // ans = max(ans,bufa);
    // now = now + bufa -1;
    bufa = 0;
    for (int i = now; i < N - 1; i++) {
      if (H[i] >= H[i + 1]) {
        bufa++;
      } else {
        break;
      }
    }

    ans = max(ans, bufa);
  }

  // OUTPUT
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define rep(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++)
#define rrep(i, a, b) for (int(i) = int(a); (i) >= int(b); (i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)1e9 + 1
#define MOD (long long)1e9 + 7
#define INF64 (long long)1e18 + 1

#define F first
#define S second

#define Pii pair<int, int>
#define Pll pair<long long, long long>
#define Piii pair<int, pair<int, int>>
#define Plll pair<long long, pair<long long, long long>>

#define Vll(a, b, c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a, b, c, d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main(void) {
  // INPUT
  llint N;
  cin >> N;
  vector<llint> H(N);
  rep(i, 0, N) {
    llint bufh;
    cin >> H[i];
  }

  // SOLVE
  llint ans = 0;
  llint now;
  llint bufa;
  for (now = 0; now < N; now++) {
    // auto itl = upper_bound(H.begin()+now,H.end(), H[now]);
    // bufa = H.end() - (H.begin()+now);
    // ans = max(ans,bufa);
    // now = now + bufa -1;
    bufa = 0;
    for (int i = now; i < N - 1; i++) {
      if (H[i] >= H[i + 1]) {
        bufa++;
      } else {
        break;
      }
    }

    now += bufa;

    ans = max(ans, bufa);
  }

  // OUTPUT
  cout << ans << endl;

  return 0;
}