cswork / OAOpen practice workspace

DellOA #1

Optimizing Resource Allocation

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersHashing

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.

Input

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

Output a single integer, the answer.

Example 1

Input:

6 3
1 2 3 7 3 5

Output:

15

Example 2

Input:

3 2
-5 -2 -3

Output:

-5

Example 3

Input:

2 2
1 1

Output:

-1

Example notes

The outputs of the three public examples are, in order: 15; -5; -1. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…