이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Challenge: Accepted
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <stack>
#include <set>
#define ll long long
#define maxn 3005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll a[maxn], pref[maxn];
int dp[maxn][maxn];
int solve(int n) {
for (int i = 0;i < n;i++) {
for (int j = 0;j <= i;j++) {
if (j == 0) {
dp[i][j] = 1;
} else {
for (int k = j - 1;k >= 0;k--) {
if (pref[i] - pref[j - 1] >= pref[j - 1] - (k ? pref[k - 1] :0)) {
dp[i][j] = max(dp[i][j], dp[j - 1][k] + 1);
}
}
}
}
}
int ret = 0;
for (int i = 0;i < n;i++) ret = max(ret, dp[n - 1][i]);
return ret;
}
signed main() {
io
int n;
cin >> n;
for (int i = 0;i < n;i++) {
cin >> a[i];
pref[i] = a[i] + (i ? pref[i - 1] : 0);
}
cout << solve(n);
}
/*
4
2 3 1 7
5
6 2 3 9 13
3
3 1 2
*/
# | 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... |