QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 256 MB مجموع النقاط: 100

#4803. 糖果

الإحصائيات

Grammy 有一个循环数组 $a_1, a_2, \dots, a_n$。你可以按任意顺序执行以下操作若干次(可能为零次):

  • 选择两个相邻且数值相同的元素,并将它们删除。
  • 选择两个相邻且数值之和为特殊数字 $x$ 的元素,并将它们删除。

每当你成功执行一次操作,Grammy 就会给你一颗糖果。同时,数组剩余的部分会拼接在一起。例如,删除数组的第三个和第四个元素后,第二个元素和第五个元素将变得相邻。

求你能获得的最大糖果数量。

如果 $u + 1 = v$ 或者 $u = 1$ 且 $v = L$(其中 $L$ 为剩余数组的长度),则称两个位置 $u$ 和 $v$ ($u < v$) 相邻。

输入格式

第一行包含两个整数 $n$ 和 $x$ ($1 \le n \le 10^5$, $1 \le x \le 10^9$),分别表示数组的长度和特殊数字 $x$。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$),表示循环数组中的数字。

输出格式

输出一个整数,表示你能获得的最大糖果数量。

样例

输入 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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.