cswork / OA打开练习工作台

eBayOA #4

Currency Trading Strategy

估计中等可在线判题

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

Strategy values are limited to −1 (sell), 0 (hold), and +1 (buy), and the profit on day i is −strategy[i]×rate[i]. Choose exactly one contiguous window of length k and reset the strategies in that window to one of these three valid values; find the maximum total profit. Interpreting any value as any value in the set of strategy values is an explicit type convention of this site.

输入格式

n,k (1≤k≤n≤200000), rates in 0..10⁹, and strategy in −1/0/+1. The ranges are site supplements.

输出格式

Output the total profit (64-bit).

样例 1

输入:

3 1
1 1 10
0 0 1

输出:

10

样例 2

输入:

3 2
5 2 8
1 -1 0

输出:

7

样例 3

输入:

1 1
4
0

输出:

4