Logo
(追記) (追記ここまで)

25650번 - Candies 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB178857.143%

문제

Grammy has a circular array $a_1, a_2, \ldots, a_n$. You can do the following operations several (possibly zero) times in any order:

  • Choose two adjacent positions with the same number, and erase them.
  • Choose two adjacent positions such that the numbers on these positions add up to a special number $x,ドル and erase them.

After each time you do an operation successfully, Grammy will give you a candy. Meanwhile, the remaining parts of the array will be concatenated. For example, after deleting the third and fourth element of the array, the second element and the fifth element will become adjacent.

Find the maximum number of candies you can get.

Two positions $u$ and $v$ ($u<v$) are adjacent if and only if $u+1=v$ or $u=1$ and $v=L,ドル where $L$ is the length of the remaining array.

입력

The first line contains two integers $n$ and $x$ (1ドル \leq n \leq 10^5,ドル 1ドル \leq x \leq 10^9$) denoting the length of the array and the special number $x$.

The second line contains $n$ integers $a_1, a_2,\ldots, a_n$ (1ドル \leq a_i \leq 10^9$) denoting the numbers in the circular array.

출력

Output an integer denoting the maximum number of candies you can get.

제한

예제 입력 1

6 5
1 1 4 5 1 4

예제 출력 1

2

예제 입력 2

10 5
1 2 5 2 1 2 3 4 8 4

예제 출력 2

3

노트

출처

Camp > Petrozavodsk Programming Camp > Summer 2022 > Day 2: ZJU Contest 1 F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /