제출 #791737

#제출 시각아이디문제언어결과실행 시간메모리
791737minhnhatnoeFeast (NOI19_feast)C++14
0 / 100
57 ms8820 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> a; pair<ll, int> calc(ll bm){ int n = a.size(); pair<ll, int> pfmax(0, 0); pair<ll, int> prevdp(0, 0); for (int i=0; i<n; i++){ // dp[i] = max(dp[i-1], dp[k-1] + pf[i] - pf[k-1] - bm) // (dp[k-1] - pf[k-1]) + pf[i] - bm pair<ll, int> cdp = prevdp; cdp = max(cdp, pair<ll, int> (pfmax.first + a[i] - bm, pfmax.second + 1)); pfmax = max(pfmax, pair<ll, int> (cdp.first - a[i], cdp.second)); prevdp = cdp; } return prevdp; } signed main(){ cin.tie(0)->sync_with_stdio(0); int n, k; cin >> n >> k; a.resize(n); for (int i=0; i<n; i++) cin >> a[i]; partial_sum(a.begin(), a.end(), a.begin()); ll bl=0, br=1e18; vector<pair<ll, int>> dp(n); while (bl < br){ ll bm = (bl + br) >> 1; if (calc(bm).second > k) bl = bm+1; else br = bm; } pair<ll, int> s = calc(bl); cout << s.first + s.second * bl << "\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...