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<iostream>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<random>
using namespace std;
int n;
vector<int>v;
vector<vector<vector<long long>>>table;
long long rec(int indx, int k, bool last){
long long res=-1e15;
if(k < 0)return -1e15;
if(indx == n && k >= 0)return 0;
if(indx == n)return -1e15;
if(table[last][k][indx] != -1e18)return table[last][k][indx];
if(last){
res = max(rec(indx + 1, k, 1) + v[indx], rec(indx + 1, k, 0));
}
else{
res = max(rec(indx+ 1, k - 1, 1) + v[indx], rec(indx + 1, k, 0));
}
return table[last][k][indx] = res;
}
int main()
{
int k;
cin >> n >> k;
v.resize(n);
table.assign(2, vector<vector<long long>>(n, vector<long long>(n, -1e18)));
for(int i = 0;i < n;++i){
cin >> v[i];
}
cout << max(0LL, rec(0, k, 0));
}
# | 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... |