Submission #739738

#TimeUsernameProblemLanguageResultExecution timeMemory
739738ToxtaqFeast (NOI19_feast)C++17
41 / 100
111 ms262144 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...