제출 #1229239

#제출 시각아이디문제언어결과실행 시간메모리
1229239trimkusFeast (NOI19_feast)C++20
0 / 100
1057 ms23864 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N, K; cin >> N >> K; vector<ll> a(N + 1); for (int i = 1; i <= N; ++i) { cin >> a[i]; } ll left = 0, right = 1e18; ll res = 0; auto chmax = [&](array<ll, 2>& x, array<ll, 2> y, ll delta) -> void { if (delta <= 0) { y[0] += delta; y[1] += 1; } if (x[0] == y[0]) { if (x[1] > y[1]) { x = y; } } else if (x[0] < y[0]) { x = y; } }; auto calc = [&](ll now) -> array<ll, 2> { vector<vector<array<ll, 2>>> dp(N + 1, vector<array<ll, 2>>(2, {0, 0})); for (int i = 1; i <= N; ++i) { dp[i][0] = dp[i - 1][0]; chmax(dp[i][0], dp[i - 1][1], -now); dp[i][1] = dp[i - 1][0]; dp[i][1][0] += a[i]; auto ndp = dp[i - 1][1]; ndp[0] += a[i]; chmax(dp[i][1], ndp, +1); } auto res = dp[N][0]; chmax(res, dp[N][1], +1); return res; }; while (left <= right) { ll mid = (left + right) / 2; if (calc(mid)[1] > K) { left = mid + 1; } else { res = mid; right = mid - 1; } } cout << calc(res)[0] + 1LL * res * 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...