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
#define int long long
pair<int,long long> dp[500005];
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
int a[n + 1]; for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 2; i <= n; i++) a[i] += a[i - 1];
dp[0].ff = 1; dp[0].ss = 0;
for(int i = 1; i <= n; i++){
dp[i] = max(dp[i], dp[i - 1]);
int x = lower_bound(a + 1, a + n + 1, 2 * a[i] - dp[i].ss) - a;
dp[x] = max(dp[x], {dp[i].ff + 1, a[i]});
}
cout << dp[n].ff << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |