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>
#define ll int
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define pi pair<ll, pll>
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N = 5e5 + 5;
const int M = 1300;
const ll mod = 1e9 + 7;
ll n, m, t, k, ans, b[N], dp[N];
long long a[N];
vector<pll> adj[N];
vector<ll> kq;
string s[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
a[i] += a[i-1];
}
for(int i = 1; i <= n; i ++)
{
b[i] = max(b[i], b[i-1]);
dp[i] = dp[b[i]] + 1;
int j = lower_bound(a+1, a+1+n, 2*a[i]-a[b[i]]) - a;
if(j <= n)b[j] = max(b[j], i);
}
cout << dp[n];
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int test = 1;
//cin >> test;
while (test-- > 0)
sol();
return 0;
}
/*
10
4 10 2
1 2 21
1 3 13
6 7 1
7 9 5
2 4 3
2 5 8
1 6 55
6 8 34
*/
// ctrl + F8 = compile
// ctrl + F9 = run
# | 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... |