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;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<ll,pl> pll;
ll N, A[500005], P[500005], dp[500005];
pl bestr;
priority_queue<pll,vector<pll>,greater<pll> > pq;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N;
for (int i = 1; i <= N; ++i){
cin >> A[i];
P[i] = A[i] + P[i-1];
}
bestr = pl(0,0);
for (int i = 1; i <= N; ++i){
while (!pq.empty()){
pll x = pq.top();
if (x.first <= P[i]){
bestr = max(bestr,x.second);
pq.pop();
}
else break;
}
dp[i] = bestr.first+1;
pq.push(pll(2*P[i]-P[bestr.second],pl(dp[i],i)));
}
cout << dp[N] << '\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... |