#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
using ll = long long;
int a[N + 5], b[N + 5];
ll spB[2 * N + 5], dp[2 * N + 5][2];
ll getdp(int* a, int* b, int n, int k, ll bestcurr) {
dp[n - k][0] = 0; dp[n - k][1] = bestcurr;
for(int i = n - k - 1; i > 0; i--) {
bestcurr += a[i] - b[i];
bestcurr = dp[i][1] = max(a[i] - spB[i + k - 1] + spB[i - 1] + dp[i + k][0], bestcurr);
dp[i][0] = max(dp[i + 1][0], dp[i + 1][1]);
}
return max(dp[1][0], dp[1][1]);
}
int main()
{
//ifstream cin("homecoming.in");
//ofstream cout("homecoming.out");
int t, n, k;
cin >> t;
while(t--) {
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i];
if(n == k) {
ll sum = 0;
for(int i = 0; i < n; i++) sum += a[i] - b[i];
cout << max(sum, 0ll) << "\n";
} else {
for(int i = 0; i < n; i++)
spB[i] = (i > 0 ? b[i] + spB[i - 1] : b[0]);
ll res = getdp(a, b, n, k, a[n - k] - spB[n - 1] + spB[n - k - 1]);
int profit0 = a[0] - spB[k - 1];
for(int i = 0; i < k; i++) spB[i] = 0;
for(int i = n; i < n + k; i++) {
dp[i][0] = 0;
spB[i] = spB[i - 1];
}
res = max(res, profit0 + getdp(a, b, n + k, k, profit0));
cout << res << "\n";
}
}
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccXDhPb8.o: in function `main':
homecoming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwuO876.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccwuO876.o: in function `main':
grader.cpp:(.text.startup+0xdf): undefined reference to `solve(int, int, int*, int*)'
collect2: error: ld returned 1 exit status