이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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)(4e6+100))
#define MAX ((ll)(1e12+100))
ll a[ARRS];
ll b[ARRS];
ll s[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);
vector<ll> ps;
for(int i=0; i<n; i++)
if(A[i]>=B[i])ps.pb(i);
pair<ll,ll> mn={MAX,MAX};
for(int i=1; i<=2*n; i++){
ll sm=0;
for(int j=i; abs(i-j)<n&&j<=2*n; j++){
sm-=A[j]-B[j];
mn=min(mn,{sm,j-1});
}
}
ll s=mn.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;
}
# | 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... |