UberOA #4
Currency Trading Strategy
估计中等评测数据准备中,可先阅读题面
Given rates[i] (the value on day i) and strategy[i] ∈ {-1, 0, 1} (sell / hold / buy), the base profit is sum(strategy[i] * rates[i]). You may modify the strategy in exactly one contiguous window of length k (where k is even): within that window the first half is held (0) and the second half is all sold (-1, contributing +rates[i]). Find the maximum total profit achievable.
Constraints
- 1 ≤
rates.length = strategy.length = n≤ 10⁵ - 1 ≤
rates[i]≤ 10⁹ strategy[i] ∈ {-1, 0, 1}kis a positive even integer withk ≤ n
rates = [2, 4, 1, 5, 10, 6]
strategy = [-1, 1, 0, 1, -1, 0]
k = 4
solution(rates, strategy, k) = 18