# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
853931 | Trisanu_Das | Bigger segments (IZhO19_segments) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
pair<int,long long> dp[500005];
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
int a[n]; for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 1; i < n; i++) a[i] += a[i - 1];
dp[0][0] = 1; dp[0][1] = 0;
for(int i = 1; i < n; i++){
dp[i] = max(dp[i], dp[i - 1]);
int x = lower_bound(a, a + n, 2 * a[i] - dp[i].ss) - a;
dp[x] = max(dp[x], {dp[i].ff + 1, a[i]});
}
cout << dp[n - 1].ff << '\n';
}