cswork / OAOpen practice workspace

MicrosoftOA #40

Maximize Types After Freeing Shelves

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersHashing

Clear exactly R consecutive shelves without changing the order of the other shelves, and find the maximum number of distinct types among the remaining shelves. The original site's answer of 2 for the first example is incorrect; this site corrected it to 3 according to the definition.

Input

The first line contains N R (1≤N≤100000, 1≤R≤N), and the second line contains N types (1..100000).

Output

Output a single integer, the answer.

Example 1

Input:

7 3
2 1 2 3 2 3 2

Output:

3

Example 2

Input:

5 2
2 3 1 1 2

Output:

3

Example 3

Input:

3 3
1 100000 1

Output:

0

Example notes

Example 1: after deleting 0-based indices 2, 3, 4, the remaining 2, 1, 3, 2 keep three types, which is all three types of the original array; the original site's answer of 2 missed this option.

Example 2: deleting the last 2 cells leaves 2, 3, 1, keeping 3 types.

Example 3: all shelves are deleted and no type remains, so the answer is 0.

Editorial

Loading solution…