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>
#define F first
#define S second
using namespace std;
const int N = 5e5 + 5;
int n,a[N];
long long pref[N];
pair<int,long long> dp[N];
int 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[1] = {1,a[1]};
for(int i = 2; i <= n; i++){
dp[i] = {dp[i - 1].F,pref[i]};
for(int j = 1; j < i; j++){
if(pref[i] - pref[j] >= dp[j].S && dp[i].F <= dp[j].F + 1){
dp[i] = {dp[j].F + 1,pref[i] - pref[j]};
}
}
}
cout << dp[n].F;
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... |