- 最大的和
滑动窗口
#include <iostream>
#define int long long
using namespace std;
signed main()
{int n, k, sum = 0, a[101001], b[100101], c[100101];cin >> n >> k;for (int i = 1; i <= n; i++){cin >> a[i];}for (int i = 1; i <= n; i++){cin >> c[i];if (c[i] == 1){sum += a[i];b[i] = b[i - 1];}else{b[i] = b[i - 1] + a[i];}if (i > k)if (c[i-k] == 0)b[i] -= a[i - k];}int maxn = 0;for (int i = 1; i <= n; i++){if (b[i] > maxn)maxn = b[i];}sum += maxn;cout << sum << endl;
}