AmazonOA #212
Get Maximum Count
Estimated MediumJudge-ready
Choose a contiguous range at most once and add the same arbitrary integer x to every number in it, maximizing the number of elements in the whole array equal to k. x may be negative or 0, and you may also skip the operation.
Input
The first line contains n k; the second line contains the array. 1≤n≤200000; 1≤element,k≤200000.
Output
Output a single integer, the answer.
Example 1
Input:
6 2
2 3 2 4 3 2
Output:
4
Example 2
Input:
6 6
6 4 4 6 4 4
Output:
5
Example 3
Input:
3 1
1 1 1
Output:
3
Example notes
The answers are 4, 5 and 3.
Editorial
Loading solution…