Submission #1316502

#TimeUsernameProblemLanguageResultExecution timeMemory
1316502samarthkulkarniFeast (NOI19_feast)C++20
41 / 100
664 ms63836 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define vi vector<long long> #define all(x) x.begin(), x.end() #define endl "\n" void solution(); int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); solution(); return 0; } const int N = 2010; const long long inf = 1e18; ll dp[N][N][2]; ll n, k; ll a[N]; ll solve(ll i, ll j, bool f) { if (i == n+1) return 0; if (j > k) return 0; if (dp[i][j][f] != inf) return dp[i][j][f]; ll ans = 0; // take ans = max(ans, a[i] + solve(i+1, j+1, 1)); ans = max(ans, a[i] + solve(i+1, j, 1)); // don;t take ans = max(ans, solve(i+1, (f?j+1 : j), 0)); return dp[i][j][f] = ans; } void solution() { cin >> n >> k; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int l = 0; l < 2; l++) { dp[i][j][l] = inf; } } } for (int i = 1; i <= n; i++) cin >> a[i]; cout << solve(1, 1, 0) << endl; }
#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...