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;
int n, a[500001], dp[500001];
long long pr[500001], seg[500001];
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
pr[i] = pr[i - 1] + a[i];
}
set < pair < long long, int > > s;
s.insert({0, 0});
for(int i = 1; i <= n; i++){
int j = 0;
while(!s.empty()){
if((s.begin()->first) > pr[i]) break;
j = max(j, s.begin() -> second);
s.erase(s.begin());
}
dp[i] = dp[j] + 1;
seg[i] = pr[i] - pr[j];
s.insert({pr[j] + seg[j], j});
s.insert({pr[i] + seg[i], i});
}
cout << dp[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... |