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;
typedef long long ll;
int n,k;
vector<ll> W;
vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(2005, vector<ll>(2005, -1)));
ll solve(int i, int l, bool w) {
if(dp[w][i][l] != -1) return dp[w][i][l];
if(l > k || i >= n) return 0;
ll ans = numeric_limits<int>::min();
if(w == false) {
ans = max(ans, solve(i+1, l , false));
ans = max(ans, solve(i+1, l+1, true));
} else {
ans = max(ans, solve(i+1, l, true));
ans = max(ans, solve(i+1, l, false));
}
ans += (w) ? W[i] : 0;
dp[w][i][l] = ans;
return ans;
}
int main() {
cin >> n >> k;
W.resize(n); for(auto &a : W) cin >> a;
cout << max(solve(0, 0, false), solve(0, 1, true));
}
# | 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... |