Reference to 機動戦士ガンダム 水星の魔女
Enemies are surrounding us!
You are currently situated in a battlefield where $N$ enemies are around you. Your mobile suit is unable to move but is given a rail gun with the range $R$, which it can shoot down enemies if the distance between the suit and the enemy is less than or equal to $R$.
Luckily, you have a radar that can show the distance between the mobile suit and the N enemies surrounding you. The radar will show you $N$ integers, $X_1$, $X_2$, ..., $X_N$. For the $i$ th enemy, the distance between it and the mobile suit is denoted as $X_i$.
Can you figure out how many enemies you can defeat with the railgun you have?
Input
The first line consists of 2 integers, $N$, $R$. ($1 \le N \le 10^5$, $1 \le R \le 10^9$)
The second line consists of $N$ integers, $X_1$, $X_2$, ..., $X_N$, the readings of the radar. ($1 \le X_i \le 10^9$ for all $1 \le i \le N$)
Output
The output consists of a single integer, the number of enemies you can defeat.
Subtasks
Subtask 1: $N = 1$ (10 pts)
Subtask 2: $N = 2$ (15 pts)
Subtask 3: $N = 3$ (25 pts)
Subtask 4: No additional constraints (50 pts)
Sample Test Cases
| Input | Output | |
|---|---|---|
| 3 5 4 2 9 |
2 | |
The rail gun can shoot down enemies with distances 2 and 4 only. |
||
Scoring: Per Subtask
Authored by wy23918
Appeared in WYHK 2026 Mini Comp 0 🗣️🙊🇫🇷🥖🤮 🟥🟦3️⃣2️⃣1️⃣🎊 8️⃣0️⃣🧙♀️ 🇩🇪🏙️🌍🦠🧑💻💃🌧️