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 pb push_back
#define F first
#define S second
#define sz(x) (int)x.size()
#define sbb (x & (-x))
#define all(x) begin(x), end(x)
using namespace std;
typedef long long llong;
typedef pair <llong, int> pii;
const int MXN = 4e5 + 7;
const int MOD = 1e9 + 7;
const llong INF = 1e18 + 7;
const int N = 2e5;
int n, a[MXN], dp[MXN];
llong pref[MXN], mx[MXN];
int main(){
ios_base::sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
dp[1] = 1;
for(int i = 1; i <= n; i++){
int k = i;
for(; k >= 1; k--){
if(pref[i] - pref[k - 1] >= mx[k - 1]) break;
}
dp[i] = dp[k - 1] + 1;
mx[i] = pref[i] - pref[k - 1];
}
cout << dp[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... |