This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//I wrote this code 4 u <3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
signed main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<ll> pref(n + 1);
partial_sum(a.begin(), a.end(), pref.begin() + 1);
vector<int> dp(n + 1), id(n + 2);
for (int i = 1; i <= n; ++i) {
id[i] = max(id[i], id[i - 1]);
dp[i] = dp[id[i]] + 1;
int j = lower_bound(pref.begin() + 1, pref.end(), 2 * pref[i] - pref[id[i]]) - pref.begin();
id[j] = max(id[j], i);
}
cout << dp[n];
}
/*
*/
# | 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... |