제출 #1122214

#제출 시각아이디문제언어결과실행 시간메모리
1122214minggaFeast (NOI19_feast)C++17
0 / 100
86 ms14896 KiB
#include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define int long long const int mod = 1e9 + 7; const int inf = 2e18; const int N = 3e5 + 7; int n, k, a[N]; pair<int, int> dp[N][2]; pair<int, int> calc(int pen) { for(int i = 2; i <= n; i++) { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = max(make_pair(dp[i - 1][1].fi + a[i], dp[i - 1][1].se), make_pair(dp[i - 1][0].fi + a[i] - pen, dp[i - 1][0].se + 1)); } return max(dp[n][0], dp[n][1]); } signed main() { cin.tie(0) -> sync_with_stdio(0); cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; dp[0][0] = {0, 0}; dp[0][1] = {-inf, 0}; int l = 0, r = 1e18; int ans = 0; while(l <= r) { int m = (l + r) >> 1; if(calc(m).se >= k) { ans = m; l = m + 1; } else r = m - 1; } cout << calc(ans).fi + k *ans; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }
#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...