#include<bits/stdc++.h>
#define s second
#define f first
using namespace std;
using ll = long long;
pair<int, ll> f(pair<int, ll> a, pair<int, ll> b) {
if(a.f > b.f) return a;
else if(a.f < b.f) return b;
else if(a.s < b.s) return a;
else return b;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<ll> a(n + 1), p(n + 1, 0);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= n; i++) {
p[i] = p[i - 1] + a[i];
}
int dp[n + 1] {}, pid[n + 2] {};
for(int i = 1; i <= n; i++) {
pid[i] = max(pid[i], pid[i - 1]);
dp[i] = dp[pid[i]] + 1;
int x = n + 1;
if(p.back() >= p[i] * 2 - p[pid[i]]) x = lower_bound(p.begin(), p.end(), p[i] * 2 - p[pid[i]]) - p.begin();
pid[x] = max(pid[x], i);
}
cout << dp[n] << '\n';
return 0;
}
# | 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... |