Submission #588017

#TimeUsernameProblemLanguageResultExecution timeMemory
588017sofapudenFeast (NOI19_feast)C++14
18 / 100
154 ms26736 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll mn = -(1ll<<60); void solve(){ int n, k; cin >> n >> k; vector<ll> v(n); for(auto &x : v)cin >> x; ll l = 0, r = (1ll<<42), bes = 0; vector<vector<pair<ll,ll>>> dp(n,vector<pair<ll,ll>>(2)); while(l<=r){ ll m = (l+r)>>1; dp[0][0] = {0,0}; dp[0][1] = {-m+v[0],1}; for(int i = 1; i < n; ++i){ dp[i][0] = max(dp[i-1][0],dp[i-1][1]); dp[i][1] = max(dp[i-1][1],{dp[i-1][0].first-m,dp[i-1][0].second+1}); dp[i][1].first+=v[i]; } pair<ll,ll> b = max(dp[n-1][0], dp[n-1][1]); if(b.second >= k){ bes = b.first + m*k; l = m+1; } else{ r = m-1; } } cout << bes << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#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...