| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1288855 | red_souls | Feast (NOI19_feast) | C++20 | 1096 ms | 13772 KiB |
#include <bits/stdc++.h>
#define ll long long
#define task "Feast"
using namespace std;
const int N = 3e5 + 16;
const ll INF = 1e18;
int n, q;
ll a[N];
namespace sub6 {
ll dp[2016][2016], prefix[N];
void solve() {
for (int i = 1; i <= n; i++) {
prefix[i] = prefix[i - 1] + a[i];
}
for (int k = 1; k <= q; k++) {
for (int i = 1; i <= n; i++) {
dp[k][i] = max(dp[k][i], dp[k][i - 1]);
for (int j = 1; j <= i; j++) {
dp[k][i] = max(dp[k][i], dp[k - 1][j - 1] + prefix[i] - prefix[j - 1]);
}
}
}
cout << dp[q][n];
}
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sub6 :: solve();
return 0;
}
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... | ||||
