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;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define int long long
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
const int E = 5e5+777;
const long long inf = 1e18+777;
const int N = 3e3+777;
const int MOD = 1e9+7;
int n, a[E], pref[E];
pair<int,int> dp[E];
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];
}
for(int i = 1; i <= n; ++i){
dp[i] = {0, 1};
}
for(int i = 1; i <= n; ++i){
for(int j = 0; j <= i; ++j){
if(pref[i] - pref[j] >= pref[j] - pref[dp[j].S]){
dp[i] = max(dp[i], {dp[j].first+1, j});
}
}
}
// for(int i = 1; i <= n; ++i){
// cerr << i << " -> " << dp[i].first << ' ' << dp[i].second << '\n';
// }
cout << dp[n].F;
}
# | 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... |