This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#include"homecoming.h"
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
int n, k;
vector<ll> a, b;
vector<int> tooka, tookb;
ll naive1() {
ll ans = 0, cur = 0;
while(true) {
array<ll, 2> best = {-1, -1};
ll sm = 0;
for(int i = 0; i < k; i++) {
sm += b[i]*!tookb[i];
}
for(int i = 0; i < n; i++) {
if(!tooka[i]) {
best = max(best, {a[i]-sm, i});
}
sm -= b[i]*!tookb[i];
sm += b[(i+k)%n]*!tookb[(i+k)%n];
}
if(best[1] == -1) break;
cur += best[0];
tooka[best[1]] = 1;
for(int i = 0; i < k; i++) tookb[(best[1]+i)%n]=1;
ans = max(ans, cur);
}
return ans;
}
long long solve(int N, int K, int *A, int *B) {
n = N, k = K;
a = vector<ll>(A, A+n);
b = vector<ll>(B, B+n);
tooka = tookb = vector<int>(n, 0);
return naive1();
}
# | 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... |