이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e3+3, inf = LLONG_MAX;
int n, a[N], pre[N], dp[N][N];
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dp[i][j] = inf;
}
}
cin >> n;
a[0] = pre[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = a[i] + pre[i-1];
}
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (dp[i][j] == inf) continue;
// no hago grupo nuevo
dp[i+1][j] = min(dp[i+1][j], dp[i][j] + a[i+1]);
// hago grupo nuevo
int l = i+1;
int r = n+1;
while (l < r) {
int mid = (l+r)/2;
int x = pre[mid] - pre[i];
if (x >= dp[i][j]) r = mid;
else l = mid+1;
}
if (r == n+1) continue; // cogiendo todos sigue siendo menor
dp[l][j+1] = min(dp[l][j+1], pre[l] - pre[i]);
}
}
int ans;
for (int i = n; i >= 1; i--) {
if (dp[n][i] != inf) {
ans = i;
break;
}
}
cout << ans << "\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... |