Submission #1094224

#TimeUsernameProblemLanguageResultExecution timeMemory
1094224Trisanu_DasFeast (NOI19_feast)C++17
59 / 100
1098 ms7772 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a[n], dp[2][k + 1], ans[2][k + 1]; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++){ for(int j = 1; j <= k; j++){ dp[i & 1][j] = max(dp[(i + 1) & 1][j], ans[(i + 1) & 1][j - 1]) + a[i]; ans[i & 1][j] = max(ans[(i + 1) & 1][j], dp[i & 1][j]); } } cout << ans[(n + 1) & 1][k] << '\n'; }
#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...