MicrosoftOA #40
Maximize Types After Freeing Shelves
估计中等可在线判题
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.
输入格式
The first line contains N R (1≤N≤100000, 1≤R≤N), and the second line contains N types (1..100000).
输出格式
Output a single integer, the answer.
样例 1
输入:
7 3
2 1 2 3 2 3 2
输出:
3
样例 2
输入:
5 2
2 3 1 1 2
输出:
3
样例 3
输入:
3 3
1 100000 1
输出:
0
样例说明
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.