#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
#define lb lower_bound
#define ub upper_bound
const ll MAXN=200001;
const ll MOD=1e9+7;
const ll INF = 3e9;
ll A[MAXN];
ll N;
ll dp[MAXN];
ll S[MAXN];
int main(){
cin>>N;
for(int i=1;i<=N;++i){
cin>>A[i];
A[i]+=A[i-1];
}
dp[0]=0;
S[0]=0;
for(int i=1;i<=N;++i){
for(int j=1;j<=i;++j){
// take from i to j
ll x=A[i];
// cerr<<i<<' '<<j<<' '<<x<<'\n';
if(x >= S[j-1]){
if(dp[j-1]+1 >= dp[i]){
dp[i]=dp[j-1]+1;
S[i] = x+A[i];
}
}
}
// cerr<<i<<' '<<dp[i]<<'\n';
}
cout<<dp[N];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |