Skip to content

Instantly share code, notes, and snippets.

@velicast
Last active December 18, 2015 15:09
Show Gist options
  • Save velicast/5802433 to your computer and use it in GitHub Desktop.
Save velicast/5802433 to your computer and use it in GitHub Desktop.
Dynamic Programming solution to problem http://codeforces.com/problemset/problem/66/B
#include <bits/stdc++.h>
using namespace std;
int l[1024],r[1024],h[1024];
int main() {
int n,res = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 1; i < n; ++i) {
if (h[i] >= h[i - 1]) {
l[i] = 1+l[i-1];
}
}
for (int i = n - 2; i >= 0; --i) {
if (h[i] >= h[i+1]) {
r[i] = 1+r[i+1];
}
}
for (int i = 0; i < n; ++i) {
res = max(res,1+l[i]+r[i]);
}
cout << res << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment