A - Save the Monsters 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 500500

問題文

11 から NN までの番号がついた NN 体のモンスターをあなたは飼っています.

あなたのモンスターを討伐するために勇者がやってきました. 勇者はこれから MM ターンかけてモンスターに攻撃を仕掛けます. ii ターン目には,勇者は以下のいずれかの行動を行います.

  • MP を 11 消費してモンスター XiX_i を攻撃する. この行動は,モンスター XiX_i がまだ生きており,かつ勇者の MP が 11 以上のときにのみ行える.

  • 何もしない.

勇者が攻撃を行った場合,あなたはそれに対して以下のいずれかの行動を行います.

  • MP を 11 消費してモンスター XiX_i を守る. この行動はあなたの MP が 11 以上のときにのみ行える.

  • 何もしない.このとき,モンスター XiX_i は死んでしまう.

最初のターンが始まる前の段階で,勇者の MP は AA,あなたの MP は BB です. また,勇者もあなたも N,M,A,B,XiN,M,A,B,X_i の値をすべて把握しています. このとき,以下の条件をみたす最大の整数 kk を求めてください.

  • あなたが適切な戦略を取ることで,勇者がどのように行動したとしても,kk 体以上のモンスターを最後まで生存させることができる.

制約

  • 1N,M2500001 \leq N,M \leq 250000
  • 1BAM1 \leq B \leq A \leq M
  • 1XiN1 \leq X_i \leq N
  • 入力される値はすべて整数.

入力

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

NN MM AA BB
X1X_1 X2X_2 \cdots XMX_M

出力

答えを出力せよ.


入力例 1Copy

Copy
2 3 2 1
1 2 1

出力例 1Copy

Copy
1

あなたは 11 体以上のモンスターを必ず生存させることができます.

以下にありうる進行の一例を示します.

  • 11 ターン目: 勇者がモンスター 11 を攻撃する.
    • あなたは何もせず,モンスター 11 が死ぬ.
  • 22 ターン目: 勇者がモンスター 22 を攻撃する.
    • あなたはモンスター 22 を守る.
  • 33 ターン目: 勇者はなにもしない.

入力例 2Copy

Copy
2 6 3 2
1 1 1 2 2 2

出力例 2Copy

Copy
1

入力例 3Copy

Copy
100 1 1 1
100

出力例 3Copy

Copy
100

入力例 4Copy

Copy
6 20 16 5
5 6 1 3 2 1 4 3 2 4 1 4 4 6 3 3 5 2 2 2

出力例 4Copy

Copy
2

Score : 500500 points

Problem Statement

You keep NN monsters numbered 11 to NN.

A hero has come to slay your monsters. He will take MM turns to attack the monsters. In the ii-th turn, he performs one of the following actions.

  • Consume 11 MP to attack monster XiX_i. This action can only be performed when monster XiX_i is still alive and the hero has at least 11 MP.

  • Do nothing.

If the hero attacks, you will respond by performing one of the following actions.

  • Consume 11 MP to defend monster XiX_i. This action can only be performed when you have at least 11 MP.

  • Do nothing. The monster will die.

Before the first turn begins, the hero has AA MP, and you have BB MP. Both you and the hero know all values of NN, MM, AA, BB, and XiX_i. Find the greatest integer kk that satisfies the following condition.

  • By using an appropriate strategy, you can keep at least kk monsters alive no matter how the hero acts.

Constraints

  • 1N,M2500001 \leq N,M \leq 250000
  • 1BAM1 \leq B \leq A \leq M
  • 1XiN1 \leq X_i \leq N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM AA BB
X1X_1 X2X_2 \cdots XMX_M

Output

Print the answer.


Sample Input 1Copy

Copy
2 3 2 1
1 2 1

Sample Output 1Copy

Copy
1

You can always keep at least one monster alive.

Here is one possible progression.

  • The first turn: The hero attacks monster 11.
    • You do nothing, and monster 11 dies.
  • The second turn: The hero attacks monster 22.
    • You defend monster 22.
  • The third turn: The hero does nothing.

Sample Input 2Copy

Copy
2 6 3 2
1 1 1 2 2 2

Sample Output 2Copy

Copy
1

Sample Input 3Copy

Copy
100 1 1 1
100

Sample Output 3Copy

Copy
100

Sample Input 4Copy

Copy
6 20 16 5
5 6 1 3 2 1 4 3 2 4 1 4 4 6 3 3 5 2 2 2

Sample Output 4Copy

Copy
2


2025-03-14 (金)
13:45:01 +00:00