# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
778852 | doowey | Feast (NOI19_feast) | C++14 | 130 ms | 10412 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)3e5 + 10;
const ll inf = (ll)1e18;
ll P[N];
pii dp[N];
int n;
void compute(ll penalty){
for(int i = 1 ; i <= n; i ++ ){
dp[i]=mp(-inf,0);
}
pii cur=mp(dp[0].fi-P[0]-penalty, 1);
for(int i = 1; i <= n; i ++ ){
dp[i]=max(dp[i-1],mp(cur.fi+P[i],cur.se));
cur=max(cur,mp(dp[i].fi-P[i]-penalty,dp[i].se+1));
}
}
int main(){
fastIO;
int k;
cin >> n >> k;
for(int i = 1; i <= n; i ++ ){
cin >> P[i];
P[i]+=P[i-1];
}
ll lf = 0ll;
ll rf = (ll)1e18;
ll mid;
ll penalty;
while(lf < rf){
mid = (lf + rf) / 2;
compute(mid);
if(dp[n].se > k){
lf=mid+1;
}
else{
rf=mid;
}
}
compute(lf);
cout << dp[n].fi + dp[n].se * 1ll * lf << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |