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 <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
void solve(){
int n;
cin >> n;
vector<ll> a(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
vector<ll> pf(n+1, 0);
for(int i = 1; i <= n; i++){
pf[i] = pf[i-1]+a[i];
}
auto sum = [&](int l, int r) -> ll{
return pf[r]-pf[l-1];
};
auto chmax = [&](pair<ll, ll> &a, pair<ll, ll> b){
if(a.first < b.first){
a = b;
}else if(a.first == b.first){
if(a.second > b.second){
a = b;
}
}
};
vector<pair<ll, ll>> f(n+1, {-INF, 0});
f[0] = {0, 0};
for(int i = 1; i <= n; i++){
for(int j = 1; j <= i; j++){
if(sum(j, i) >= f[j-1].second){
chmax(f[i], {f[j-1].first+1, sum(j, i)});
}
}
}
cout << f[n].first;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | 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... |