#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 |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
13648 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
129 ms |
55412 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
8 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
31 ms |
13648 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
129 ms |
55412 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
8 ms |
2516 KB |
Output is correct |
16 |
Correct |
125 ms |
55348 KB |
Output is correct |
17 |
Correct |
68 ms |
20060 KB |
Output is correct |
18 |
Correct |
124 ms |
38444 KB |
Output is correct |
19 |
Correct |
95 ms |
35368 KB |
Output is correct |
20 |
Correct |
103 ms |
38508 KB |
Output is correct |
21 |
Correct |
95 ms |
32856 KB |
Output is correct |