Submission #1017465

#TimeUsernameProblemLanguageResultExecution timeMemory
1017465vjudge1Feast (NOI19_feast)C++17
100 / 100
154 ms12364 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define pb push_back #define pf push_front #define fi first #define se second const ll mod = 1e9+7, mxn = 3e5+7; ll n, a[mxn], k; pair<ll,ll> lmb(ll x) { pair<ll,ll> dp[mxn][2]; dp[1][0] = {0,0}; dp[1][1] = {a[1]-x,1}; for (ll 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][0].fi+a[i]-x,dp[i-1][0].se+1), make_pair(dp[i-1][1].fi+a[i],dp[i-1][1].se)); } return max(dp[n][0],dp[n][1]); } void aliens() { ll l = 0, r = 1e18, ans = -1; while (r >= l) { ll m = (r+l)>>1; pair<ll,ll> opt = lmb(m); if (opt.se <= k) { ans = max(ans,opt.fi+m*opt.se); r = m-1; } else l = m+1; } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr); cin >> n >> k; for (ll i = 1; i <= n; i++) cin >> a[i]; aliens(); }
#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...