# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
224685 | Nightlight | Feast (NOI19_feast) | C++14 | 16 ms | 4352 KiB |
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;
int N, K;
long long pre[3005];
long long dp[3005][3005];
long long ans = 0;
//udah ambil berapa, ada dimana
int main() {
// freopen("inp", "r", stdin);
scanf("%d %d", &N, &K);
for(int i = 1; i <= N; i++) {
scanf("%lld", &pre[i]);
cout << pre[i] << " ";
pre[i] += pre[i - 1];
}
puts("");
//i = sudah ambil berapa
//j = ada dimana
for(int i = 1; i <= K; i++) {
long long best = dp[i - 1][i - 1] - pre[i - 1];
long long bestdp = dp[i - 1][i - 1];
for(int j = i; j <= N; j++) {
dp[i][j] = pre[j] + best;
bestdp = max(dp[i - 1][j], bestdp);
best = max(best, bestdp - pre[j]);
ans = max(ans, dp[i][j]);
}
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |