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>
#ifdef LOCAL
#include "../prettyprint.hpp"
#define cerr cout
#define debug(x) cerr << "\033[36m"<< __LINE__ << ":\033[39m " << (#x) << " = " << (x) << '\n'
#else
#define cerr if(false) cout
#define debug(x) 42
#endif
using namespace std;
using ll = long long;
const int N = 3030;
int n;
int a[N];
ll s[N];
int dp[N];
ll opt[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++)
s[i] = s[i - 1] + a[i];
dp[0] = 0; opt[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
if (s[i] >= opt[j] + s[j]) {
dp[i] = dp[j] + 1;
opt[i] = s[i] - s[j];
}
}
}
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... |