#include <bits/stdc++.h>
#include "homecoming.h"
using namespace std;
long long solve(int n, int k, int *a, int *b){
long long cur, cost, nextcost, maxi = INT_MIN, maxj = INT_MIN;
cost = accumulate(b, b + k, 0ll);
maxi = a[0] - cost;
cur = a[0] - cost;
for(int i = 1; i < n; i++){
cost -= b[i - 1];
if(i + k - 1 < n) nextcost = b[k + i - 1];
else nextcost = 0;
cur = max(cur + a[i] - nextcost, maxi + a[i] - (cost + nextcost));
maxi = max(maxi, cur);
cost += nextcost;
}
cost = accumulate(b, b + k, 0ll);
maxj = max(0ll, a[0] - cost);
cur = a[0] - cost;
for(int i = 1; i < n; i++){
cost -= b[i - 1];
if(i + k - 1 < n) nextcost = b[k + i - 1];
else nextcost = b[k + i - 1 - n];
cur = max(cur + a[i] - nextcost, maxj + a[i] - (cost + nextcost));
maxj = max(maxj, cur);
cost += nextcost;
}
maxi = max(maxi, maxj);
return maxi;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
568 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
92 ms |
55612 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
6 ms |
2612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
568 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
22 ms |
4188 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
92 ms |
55612 KB |
Output is correct |
14 |
Correct |
2 ms |
856 KB |
Output is correct |
15 |
Correct |
6 ms |
2612 KB |
Output is correct |
16 |
Correct |
91 ms |
55556 KB |
Output is correct |
17 |
Correct |
47 ms |
20012 KB |
Output is correct |
18 |
Correct |
89 ms |
38452 KB |
Output is correct |
19 |
Correct |
67 ms |
35420 KB |
Output is correct |
20 |
Correct |
58 ms |
38612 KB |
Output is correct |
21 |
Correct |
67 ms |
33036 KB |
Output is correct |