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 int long long
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
const int NM = 5e5;
int N, a[NM+5], pref[NM+5];
pii dp[NM+5];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 1; i <= N; i++){
cin >> a[i];
pref[i] = pref[i-1]+a[i];
}
dp[0] = mp(0, 0);
for (int i = 1; i <= N; i++){
int l = 2, r = i, j = 1;
while (l <= r){
int mid = (l+r)/2;
if (pref[i]-pref[mid-1] >= dp[mid-1].se){
j = mid;
l = mid+1;
}
else r = mid-1;
}
dp[i].fi = dp[j-1].fi+1;
dp[i].se = pref[i]-pref[j-1];
}
cout << dp[N].fi;
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... |