# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486386 | KienTran | Feast (NOI19_feast) | C++14 | 136 ms | 262148 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>
#define int long long
using namespace std;
const int O = 3e5 + 5;
int n, k, a[O];
vector <vector <int>> f[2];
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++ i) cin >> a[i];
for (int i = 0; i < 2; ++ i){
f[i].resize(n + 1);
for (int j = 0; j <= n; ++ j) f[i][j].resize(k + 1);
}
for (int i = 1; i <= n; ++ i){
for (int j = 1; j <= k; ++ j){
f[0][i][j] = max(f[1][i - 1][j - 1], f[0][i - 1][j]) + a[i];
f[1][i][j] = max({f[0][i][j], f[1][i - 1][j - 1], f[1][i - 1][j]});
}
}
cout << f[1][n][k];
}
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... |