이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "homecoming.h"
long long solve(int N, int K, int *A, int *B) {
long long cost = 0, ans = 0;
for (int i = 0; i < K; i++)
cost += B[i];
long long take = A[0] - cost, leave = - 1E18L;
ans = max(ans, take);
ans = max(ans, leave);
for (int i = 1; i < N; i++) {
cost -= B[i - 1];
int new_cost = 0;
if (i + K - 1 < N)
new_cost = B[i + K - 1];
long long now_take = max(take, leave - cost) + A[i] - new_cost;
long long now_leave = max(take, leave);
cost += new_cost;
take = now_take;
leave = now_leave;
ans = max(ans, take);
ans = max(ans, leave);
}
cost = 0;
for (int i = 0; i < K; i++)
cost += B[i];
take = A[0] - cost, leave = 0LL;
ans = max(ans, take);
ans = max(ans, leave);
for (int i = 1; i < N; i++) {
cost -= B[i - 1];
int new_cost = B[(i + K - 1) % N];
long long now_take = max(take, leave - cost) + A[i] - new_cost;
long long now_leave = max(take, leave);
cost += new_cost;
take = now_take;
leave = now_leave;
ans = max(ans, take);
ans = max(ans, leave);
}
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... |