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 X first
#define Y second
typedef long long ll;
typedef pair<int, ll> pii;
const int N = 5e5 + 2;
int n, a[N];
pii dp[N];
ll pre[N];
set<pair<ll, pii> > s;
pii cmp_dp(pii x, pii y) {
if (x.X == y.X) {
if (x.Y < y.Y) return x;
return y;
}
if (x.X > y.X) return x;
return y;
}
int main(){
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
pre[0] = a[0];
for (int i = 1; i < n; ++i) pre[i] = a[i] + pre[i - 1];
for (int i = 0; i < n; ++i) {
dp[i] = {1, pre[i]};
for (int j = 0; j < i; ++j) {
if (pre[i] >= dp[j].Y + pre[j]) {
dp[i] = cmp_dp(dp[i], {dp[j].X + 1, pre[i] - pre[j]});
}
}
// pii cur = {dp[i].X, pre[i]};
// pair<ll, pii> pt = {dp[i].Y + pre[i], cur};
//
// auto it = s.lower_bound(pt);
// if (it != s.end() && (*it))
}
cout << dp[n - 1].X << "\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... |