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>
using namespace std;
#define int long long
#define endl '\n'
#define fs first
#define ss second
#define str string
#define all(a) a.begin(), a.end()
#define print(a) \
for (auto x : a) \
cout << x << ' '; \
cout << endl;
#define each(x, a) for (auto x : a)
struct node {
int s, l, r;
};
void solve()
{
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i ++)
cin >> a[i];
vector<int> pre(n + 1);
for(int i = 0; i < n; i ++)
pre[i + 1] = pre[i] + a[i];
vector<int> dp(n + 1), sum(n + 1);
deque<int> dq;
dq.push_back(0);
for(int i = 0; i < n; i ++){
int l = dq.front(), r = i;
while(l < r){
int m = (l + r + 1) >> 1;
if(pre[i + 1] - pre[m] >= sum[m])
l = m;
else
r = m - 1;
}
if(dp[i] < dp[i + 1])
dq.push_back(i);
if(dq.size() == 3)
dq.pop_front();
dp[i + 1] = dp[l] + 1;
sum[i + 1] = pre[i + 1] - pre[l];
}
cout << dp[n];
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
cout << endl;
}
}
# | 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... |