# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
69747 | khohko | Homecoming (BOI18_homecoming) | C++17 | 315 ms | 59508 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>
#include "homecoming.h"
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pb push_back
#define ARRS ((ll)(6e6+100))
#define MAX ((ll)(1e16+100))
ll a[ARRS];
ll b[ARRS];
ll s[ARRS];
ll sm[ARRS];
ll dp[ARRS][2];
ll sum(ll l,ll r){
return s[r]-s[l-1];
}
long long solve(int n, int K, int *B, int *A){
ll pas=0,p=0;
for(int i=1; i<=n; i++){
a[i]=A[i-1];
a[i+n]=A[i-1];
b[i]=B[i-1];
b[i+n]=B[i-1];
p-=a[i];
p+=b[i];
}
for(int i=1; i<=2*n; i++)s[i]=s[i-1]+a[i];
pas=max(pas,p);
pair<ll,ll> mn={MAX,MAX};
ll es=0,l=1;
vector<pair<ll,ll> > g;
multiset<ll > st;
for(int i=1; i<=2*n; i++){
sm[i]=sm[i-1]+b[i]-a[i];
}
ll s=0;
st.insert(0);
for(int i=1; i<=2*n; i++){
if(st.size()>K)st.erase(st.find(sm[i-K-1]));
st.insert(sm[i]);
ll es=-(sm[i]-*st.begin());
g.pb({es,i-1});
}
sort(g.begin(),g.end());
//for(int i=0; i<5; i++){
s=g[0].sc;
s++;
s%=n;
dp[0][0]=0;
dp[0][1]=-MAX;
for(int i=1; i<=n; i++){
dp[i][0]=dp[i-1][0];
dp[i][1]=-MAX;
if(i>=K){
dp[i][1]=max(dp[i][1],dp[i-K][0]+b[i-K+1+s]-sum(i-K+1+s,i+s));
dp[i][1]=max(dp[i][1],dp[i-1][1]+b[i-K+1+s]-a[i+s]);
}
dp[i][0]=max(dp[i][0],dp[i][1]);
//cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
}
pas=max(pas,dp[n][0]);
//}
//cout<<endl;
return pas;
}
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... |