DellOA #1
Optimizing Resource Allocation
估计中等可在线判题
Choose a contiguous window of length exactly k whose elements are pairwise distinct, maximizing the sum of its elements. If there is no valid window, output −1.
输入格式
The first line contains n k, and the second line contains n integers; when n=0, the second line may be empty. This site adds 0≤n≤200000, 1≤k≤200000, and −10^9≤a[i]≤10^9; k may be greater than n, and negative numbers are not excluded.
输出格式
Output a single integer, the answer.
样例 1
输入:
6 3
1 2 3 7 3 5
输出:
15
样例 2
输入:
3 2
-5 -2 -3
输出:
-5
样例 3
输入:
2 2
1 1
输出:
-1
样例说明
The outputs of the three public examples are, in order: 15; -5; -1. Verified by independent enumeration or direct simulation.