传送门:https://www.nowcoder.com/questionTerminal/93f2c11daeaf45959bb47e7894047085
#include <cstdio>
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 5;
int maxInterest, n, k;
int interest[MAXN], awake[MAXN];
void read() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &interest[i]);
for (int i = 1; i <= n; i++) scanf("%d", &awake[i]);
}
void solve() {
//最大兴趣值 = 清醒时的兴趣值 + k分钟叫醒的额外最大兴趣值
for (int i = 1; i <= n; i++) if (awake[i]) maxInterest += interest[i];
if (n < k) k = n; //
int curInterest = 0;
/*前缀和*/
//先计算前k分钟叫醒的额外兴趣值
for (int i = 1; i <= k; i++) if (0 == awake[i]) curInterest += interest[i];
//向后移动时计算k分钟叫醒的最大额外兴趣值
int _maxInterest = curInterest;
for (int i = k + 1; i <= n; i++) {
if (0 == awake[i]) curInterest += interest[i];
if (0 == awake[i - k]) curInterest -= interest[i - k];
if (curInterest > _maxInterest) _maxInterest = curInterest;
}
maxInterest += _maxInterest;
printf("%d\n", maxInterest);
}
int main() {
read();
solve();
return 0;
}