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;
using ll = long long;
ll ps[500005], dp[500005];
const ll inf = 1e9;
int main () {
ios::ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<ll, ll>> st;
for (int i = 1; i <= n; i++) cin >> ps[i], ps[i] += ps[i-1];
for (int i = 1; i <= n; i++) {
auto iter = upper_bound(st.begin(), st.end(), make_pair(ps[i], inf));
int j = iter == st.begin() ? 0 : (--iter)->second;
dp[i] = dp[j] + 1;
ll sum = ps[i]*2 - ps[j];
while (!st.empty() && sum < st.back().first) st.pop_back();
st.push_back({sum, i});
}
cout << dp[n] << "\n";
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... |