E - Hitting Stick Game Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 7

問題文

R ラウンドからなる棒倒しゲームをします。
各ラウンドは以下のように行われます。

  • N 本の棒を設置する。
  • 次の操作を M 回繰り返す。
    • 棒にめがけてボールを投げ、棒が倒れた本数をスコアとして記録する。
    • 倒れた棒を捨てる。
    • N 本の棒全てが捨てられた場合、残りの操作回数にかかわらずラウンドを終了する。

長さ L の整数列 s=(s_1,s_2,\ldots,s_L) が与えられます。
これが棒倒しゲーム全体のスコアを順番に記録したものとしてあり得るかどうか判定してください。

制約

  • 1 \leq R,N,M \leq 100
  • R \leq L \leq R\times M
  • 0 \leq s_i \leq N
  • 入力に含まれる値は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

R N M L
s_1 s_2 \ldots s_L

出力

整数列 s が棒倒しゲーム全体のスコアを順番に記録したものとしてあり得るならば Yes と、あり得ないならば No と出力せよ。


入力例 1

3 10 5 9
7 3 0 2 4 0 1 0 10

出力例 1

Yes

ラウンド 1 では 7,3 本の棒が倒され、ラウンド 2 では 0,2,4,0,1 本の棒が倒され、ラウンド 3 では 0,10 本の棒が倒されました。


入力例 2

1 100 3 2
10 20

出力例 2

No

入力例 3

2 100 3 5
100 10 20 30 40

出力例 3

No

入力例 4

3 30 100 5
20 20 15 15 30

出力例 4

No

Score : 7 points

Problem Statement

Let us play a game of bowling consisting of R rounds.
Each round goes as follows.

  • Place N pins.
  • Repeat the following procedure M times.
    • Throw a ball toward them, and record the number of pins knocked down as the score.
    • Remove the pins knocked down.
    • If all N pins have been removed, end the round even if this procedure is not repeated M times.

You are given a sequence of L integers: s=(s_1,s_2,\ldots,s_L).
Determine whether this can be a sequence of scores recorded in order in the whole game.

Constraints

  • 1 \leq R,N,M \leq 100
  • R \leq L \leq R\times M
  • 0 \leq s_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

R N M L
s_1 s_2 \ldots s_L

Output

If s can be a sequence of scores recorded in order in the whole game, print Yes; otherwise, print No.


Sample Input 1

3 10 5 9
7 3 0 2 4 0 1 0 10

Sample Output 1

Yes

In the first round, 7 and then 3 pins are knocked down. In the second round, 0, 2, 4, 0, and then 1 pin(s) are knocked down. In the third round, 0 and then 10 pins are knocked down.


Sample Input 2

1 100 3 2
10 20

Sample Output 2

No

Sample Input 3

2 100 3 5
100 10 20 30 40

Sample Output 3

No

Sample Input 4

3 30 100 5
20 20 15 15 30

Sample Output 4

No