题目收集
题目列表题单
返回列表

Mahjong 2

CodeforcesP0046· 2000ms· 1024 MB· ZJU Summer 2026 Contest 4原题链接
模拟dp

创建于 2026/07/17 · 更新于 2026/07/17

题目描述

You have 3M−13M - 13M−1 cards, each labeled with an integer from 111 to NNN. For every iii with 1≤i≤N1 \le i \le N1≤i≤N, there are AiA_iAi​ cards labeled iii.

Choose an integer KKK with 1≤K≤N1 \le K \le N1≤K≤N and add one additional card labeled KKK. Your goal is to make the following condition true.

Condition: You can repeat the operation below exactly MMM times and remove all cards.

  • In one operation, remove either
    • three cards with the same label, or
    • three cards whose labels are consecutive integers.

List all values of KKK for which the condition can be satisfied.

输入格式

The first line contains two integers NNN and MMM (1≤N≤5⋅1051 \le N \le 5 \cdot 10^51≤N≤5⋅105, 1≤M≤1081 \le M \le 10^81≤M≤108).

The second line contains integers A1,A2,…,ANA_1, A_2, \ldots, A_NA1​,A2​,…,AN​ (0≤Ai0 \le A_i0≤Ai​, ∑i=1NAi=3M−1\sum_{i=1}^{N} A_i = 3M - 1∑i=1N​Ai​=3M−1).

输出格式

On the first line, output LLL, the number of values of KKK that satisfy the condition.

On the second line, output all such values of KKK in increasing order.

样例输入 #1

5 4
0 4 2 2 3

样例输出 #1

2
2 5

样例输入 #2

4 1
1 0 0 1

样例输出 #2

0

样例输入 #3

8 15
7 10 4 2 8 6 3 4

样例输出 #3

3
1 4 7