#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define niga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define F first
#define S second
#define sz() size()
#define pb push_back
#define pf push_front
#define all(a) a.begin(), a.end()
#define bll(a) a.rbegin(), a.rend();
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
/*
a u t h o r (a b a);
──▒▒▒▒▒────▒▒▒▒▒────▒▒▒▒▒────▄████▄─────
─▒─▄▒─▄▒──▒─▄▒─▄▒──▒─▄▒─▄▒──███▄█▀───────
─▒▒▒▒▒▒▒──▒▒▒▒▒▒▒──▒▒▒▒▒▒▒─▐████─────────
─▒▒▒▒▒▒▒──▒▒▒▒▒▒▒──▒▒▒▒▒▒▒──█████▄───────
─▒─▒─▒─▒──▒─▒─▒─▒──▒─▒─▒─▒───▀████▀─────
*/
const ll N = 5e5 + 9, mod = 1e9 + 7, inf = 1e18;
pair <ll, ll> dp[N];
ll n,a[N];
void solve(){
cin >> n;
for (ll i = 1;i <= n; i++)cin >> a[i];
dp[1].F = 1;
dp[1].S = a[1];
for (ll i = 2;i <= n;i++){
ll s = a[i];
for (ll j = i - 1;j >= 1; j--){
if (s >= dp[j].S and dp[j].F + 1 > dp[i].F){
dp[i].F = dp[j].F + 1;
dp[i].S = s;
}
s += a[j];
}
if (!dp[i].F){
dp[i].F = dp[i-1].F;
dp[i].S = dp[i-1].S + a[i];
}
}
cout << dp[n].F;
}
signed main(){
niga;
ll aba = 1;
// file("name");
// cin >> aba;
while (aba --){
solve();
}
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... |