#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define mkp make_pair
#define txt freopen("kout.in", "r", stdin), freopen("kout.out", "w", stdout);
const int N = 200100, K = 20;
const int mod = 1e9 + 7;
void solve()
{
int n;
cin >> n;
int arr[n];
for(auto &i : arr)
cin >> i;
pair<int, int> dp[n + 5];
dp[0] = {1, arr[0]};
for(int i = 1; i < n; i++)
{
dp[i] = {dp[i - 1].first, dp[i - 1].second + arr[i]};
int l = -1, r = i - 1;
int s = arr[i];
for(int j = i - 1; j >= 0; j--)
{
if(s >= dp[j].second)
{
dp[i] = {dp[j].first + 1, s};
break;
}
s += arr[j];
}
}
for(int i = 1; i <= n; i++)
{
for(int j = i + 1; j <= n; j++)
{
if(dp[i].first != dp[j].first)
break;
if(dp[i].second > dp[j].second)
assert(0);
}
}
cout << dp[n - 1].first << '\n';
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = 1;
for (; T--; 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... |