cswork / OA打开练习工作台

Capital OneOA #10

Stock Trading with Algo Override

估计中等可在线判题

考点(AI 标注)前缀和区间双指针滑窗

Given daily stock prices prices[i] and an action array algo[i] (0 means buy, 1 means sell), the original profit is the sum of sell prices minus the sum of buy prices. You may choose one contiguous range of length exactly k and set every algo in it to 1. Find the maximum total profit achievable after the change. Assume you hold enough shares, so selling is not limited by inventory.

输入格式

The first line contains n, k; the second line contains n positive integers prices[i]; the third line contains n 0/1 values algo[i]. This site adds 1≤k≤n≤200000, 1≤prices[i]≤10^9.

输出格式

Output the maximum total profit (a signed 64-bit integer).

样例 1

输入:

7 4
2 4 1 5 2 6 7
0 1 0 0 1 0 0

输出:

21

样例 2

输入:

3 3
5 1 9
0 0 1

输出:

15

样例 3

输入:

4 1
3 8 2 5
1 1 1 1

输出:

18