제출 #1320950

#제출 시각아이디문제언어결과실행 시간메모리
1320950NValchanovFeast (NOI19_feast)C++20
59 / 100
1095 ms10900 KiB
#include <bits/stdc++.h> using namespace std; typedef long long llong; const int MAXN = 3e5 + 10; const llong INF = 4e18 + 10; int n, k; llong dp[MAXN][2][2]; int a[MAXN]; void read() { cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> a[i]; } } void solve() { llong ans = -INF; for(int j = 1; j <= k; j++) { for(int i = 1; i <= n; i++) { dp[i][j & 1][0] = max(dp[i - 1][j & 1][0], dp[i - 1][j & 1][1]); dp[i][j & 1][1] = max(dp[i - 1][j & 1][1], dp[i - 1][(j - 1) & 1][0]) + a[i]; } ans = max(ans, dp[n][j & 1][0]); ans = max(ans, dp[n][j & 1][1]); } cout << ans << endl; } int main() { read(); solve(); return 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...