Klee in Solitary Confinement

시간 제한1초메모리 제한1024 MB

요약
하나의 연속 부분 배열에 k를 더하거나 아무것도 하지 않아 전체 수열에서 가장 많이 등장하는 값의 등장 횟수를 최대로 만든다.
난이도

보통10점 중 7점

유형
배열, 누적 합, 해시맵, 그리디
정답자
아직 제출이 없습니다

문제

Since the traveler comes, People in Monstadt suddenly raise great interest in computer programming and algorithms, including Klee, the Spark Knight of the Knights of Favonius.

Source: Genshin Impact Official

Being sent to solitary confinement by Jean again, Klee decides to spend time learning the famous Mo's algorithm, which can compute with a time complexity of O(n1.5)\mathcal{O}(n^{1.5}) for some range query problem without modifications.

To check whether Klee has truly mastered the algorithm (or in fact making another bombs secretly), Jean gives her a problem of an integer sequence a_1,a_2,⋯ ,a_na\_1, a\_2, \cdots, a\_n along with some queries \[l_i,r_i]\[l\_i, r\_i] requiring her to find the mode number in the contiguous subsequence a_l_i,a_l_i+1,⋯ ,a_r_ia\_{l\_i}, a\_{l\_i + 1}, \cdots, a\_{r\_i}. The mode number is the most common number (that is to say, the number which appears the maximum number of times) in the subsequence.

With the help of Mo's algorithm, Klee solves that problem without effort, but another problem comes into her mind. Given an integer sequence a_1,a_2,⋯ ,a_na\_1, a\_2, \cdots, a\_n of length nn and an integer kk, you can perform the following operation at most once: Choose two integers ll and rr such that 1≤l≤r≤n1 \le l \le r \le n and add kk to every a_ia\_i where l≤i≤rl \le i \le r. Note that it is OK not to perform this operation. Compute the maximum occurrence of the mode number of the whole sequence if you choose to perform (or not perform) the operation optimally.

입력

There is only one test case in each test file.

The first line of the input contains two integers nn and kk (1≤n≤1061 \le n \le 10^6, −106≤k≤106-10^6 \le k \le 10^6) indicating the length of the sequence and the additive number.

The second line of the input contains nn integers a_1,a_2,⋯ ,a_na\_1, a\_2, \cdots, a\_n (−106≤a_i≤106-10^6 \le a\_i \le 10^6) indicating the original sequence.

출력

Output one line containing one integer indicating the maximum occurrence of the mode number of the whole sequence after performing (or not performing) the operation.

힌트

For the first sample test case, choose l=1l = 1 and r=2r = 2 and we'll result in the sequence 4,4,4,4,4\\{4, 4, 4, 4, 4\\}. The mode number is obviously 44 which appears 55 times.

For the second sample test case, choose l=4l = 4 and r=6r = 6 and we'll result in the sequence 3,2,3,3,3,3,3\\{3, 2, 3, 3, 3, 3, 3\\}. The mode number is 33 which appears 66 times.

For the fourth sample test case, choose not to perform the operation. The mode number is 11 and −2-2 which both appear 33 times.

예제4

  1. 예제 1

    입력
    5 2
    2 2 4 4 4
    
    예상 출력
    5
    
  2. 예제 2

    입력
    7 1
    3 2 3 2 2 2 3
    
    예상 출력
    6
    
  3. 예제 3

    입력
    7 1
    2 3 2 3 2 3 3
    
    예상 출력
    5
    
  4. 예제 4

    입력
    9 -100
    -1 -2 1 2 -1 -2 1 -2 1
    
    예상 출력
    3