이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "homecoming.h"
#define int long long
using namespace std;
// val(i+1,j) = (Apre[j] - Apre[i]) - (Bpre[j+k-1] - Bpre[i]) + dp[i]
// maximise dp - Apre + Bpre.
long long solve(signed N, signed K, signed *A, signed *B) {
int dp[N], Apre[N], Bpre[N+K], best = 0, ans = 0;
for(int i=0;i<N;i++) Apre[i]=(i?Apre[i-1]:0)+A[i];
for(int i=0;i<N+K;i++) Bpre[i]=(i?Bpre[i-1]:0)+B[i%N];
for(int i=0;i<N;i++) {
dp[i]=max(i?dp[i-1]:0,Apre[i]-Bpre[i+K-1]+best);
best=max(best,dp[i]-Apre[i]+Bpre[i]);
ans = max(ans, dp[i]);
}
best = 0;
for(int i=0;i<N;i++) {
dp[i]=max(i?dp[i-1]:(int)(-2.67e15),Apre[i]-Bpre[min(i+K-1,N-1LL)]+best);
best=max(best,dp[i]-Apre[i]+Bpre[i]);
}
ans = max(ans, dp[N-1]);
return ans;
}
# | 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... |