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 mp make_pair
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
typedef long long ll;
template<class A, class B> bool mmin(A& a, B b) {if (b < a) {a = b; return 1;} return 0;}
template<class A, class B> bool mmax(A& a, B b) {if (b > a) {a = b; return 1;} return 0;}
pair<int, ll> merg(pair<int, ll> a, pair<int, ll> b) {
if (a.x > b.x || (a.x == b.x && a.y < b.y)) return a;
return b;
}
ll a[3005], sum[3005];
pair<int, ll> dp[3005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum[i + 1] = sum[i] + a[i];
}
dp[0] = mp(0, 0);
for (int i = 1; i <= n; i++) {
dp[i] = mp(0, 0);
for (int j = 0; j < i; j++) {
if (dp[j].y <= sum[i] - sum[j]) {
pair<int, ll> now = mp(dp[j].x + 1, sum[i] - sum[j]);
dp[i] = merg(dp[i], now);
}
}
}
cout << dp[n].x;
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... |