제출 #1302325

#제출 시각아이디문제언어결과실행 시간메모리
1302325caterpillowFeast (NOI19_feast)C++17
10 / 100
1 ms576 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1e18; template<class T> void chmax(T &x, T y) { x = max(x, y); } int main() { cin.tie(0)->sync_with_stdio(0); int n, k; cin >> n >> k; assert(n <= 100 && k <= 100); vector<ll> a(n); for (ll &x : a) cin >> x; vector dp(n + 1, vector(k + 1, array<ll, 2>{-INF, -INF})); // pos, taken, closed/open dp[0][0][0] = 0; for (int i = 0; i <= n; i++) { for (int j = 0; j <= k; j++) { chmax(dp[i][j][0], dp[i][j][1]); if (j < k) chmax(dp[i][j + 1][1], dp[i][j][0]); if (i < n) { chmax(dp[i + 1][j][0], dp[i][j][0]); chmax(dp[i + 1][j][1], dp[i][j][1] + a[i]); } } } cout << dp[n][k][0] << '\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...