/**
____ ____ ____ __________________ ____ ____ ____
||I || ||c || ||e || || || ||M || ||a || ||n ||
||__|| ||__|| ||__|| ||________________|| ||__|| ||__|| ||__||
|/__\| |/__\| |/__\| |/________________\| |/__\| |/__\| |/__\|
*/
#include <iostream>
#include <chrono>
#include <vector>
#include <algorithm>
#define maxn 100005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll , ll> pll;
typedef pair <int , ll> pil;
typedef pair <ll , int> pli;
typedef long double ld;
std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;
double timePassed()
{
using namespace std::chrono;
currT = high_resolution_clock::now();
double time = duration_cast<duration<double>>(currT - startT).count();
return time * TIME_MULT;
}
int n;
int a[maxn];
pll dp[maxn];
ll pref[maxn];
void read()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
dp[1] = {1 , a[1]};
pref[0] = 0;
for(int i = 1; i <= n; i++)
pref[i] = pref[i - 1] + a[i];
for(int i = 2; i <= n; i++)
{
dp[i] = {dp[i - 1].X , dp[i - 1].Y + a[i]};
for(int j = i - 1; j >= 1; j--)
if(pref[i] - pref[j] >= dp[j].Y && /**(*/(dp[j].Y + 1 > dp[i].X) /** || (dp[j].Y + 1 == dp[i].X && dp[]) */)
{
dp[i] = {dp[j].X + 1 , pref[i] - pref[j]};
break;
}
}
//for(int i = 1; i <= n; i++)
// cout << dp[i].X << " " << dp[i].Y << endl;
cout << dp[n].X << endl;
}
int main()
{
/**#ifdef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
///startT = std::chrono::high_resolution_clock::now();
read();
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... |