Submission #1320967

#TimeUsernameProblemLanguageResultExecution timeMemory
1320967tolgaFeast (NOI19_feast)C++20
59 / 100
1095 ms6828 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<array<ll, 2>> dp1(k + 1), dp2(k + 1); // dp[i][j][0/1] = upto i with j subarrays for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { dp2[j][0] = max(dp1[j][0], dp1[j][1]); dp2[j][1] = max(dp1[j - 1][0], dp1[j][1]) + a[i - 1]; } swap(dp1, dp2); } ll ans = 0; for (int j = 1; j <= k; j++) ans = max({ans, dp1[j][0], dp1[j][1]}); cout << ans << 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...