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 <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
using namespace std;
typedef long long ll;
const int maxn=5e5+5;
ll a[maxn];
ll pref[maxn];
array < ll, 3 > dp[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i];
pref[i+1]=pref[i]+a[i];
}
dp[0]={a[0], -1, 1};
int pos=-1;
for(int i=1; i<n; i++){
while(pos<i-1 && pref[i+1]-pref[pos+2]>=dp[pos+1][0]){
pos++;
}
// cout << pref[i+1]-pref[pos+1] << endl;
if(pref[i+1]-pref[pos+1]>=dp[pos][0]){
dp[i]={pref[i+1]-pref[pos+1], pos, dp[i-1][2]+1};
pos=i;
continue;
}
dp[i]={pref[i+1]-pref[pos+1], pos, dp[i-1][2]};
}
cout << dp[n-1][2] << '\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... |