QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21365. 混み合う牛

Statistics

Farmer John の $N$ 頭の牛 $(1 \le N \le 50,000)$ が一次元の柵に沿って草を食べています。牛 $i$ は位置 $x(i)$ におり、高さは $h(i)$ です($1 \le x(i),h(i) \le 10^9$)。

牛の左側の距離 $D$ 以内に自分の高さの2倍以上の別の牛がおり、右側の距離 $D$ 以内にもそのような牛がいると、その牛は「混み合っている」と感じます($(1 \le D \le 1,000,000,000)$)。このような牛は乳量が少ないので Farmer John はその数を数えたいと思っています。手伝ってください。

入力

  • 1行目:2整数 $N$ と $D$。
  • $2..1+N$ 行目:$i+1$ 行目は整数 $x(i)$ と $h(i)$ です。$N$ 頭の位置はすべて異なります。

出力

  • 1行目:混み合っている牛の数。

入出力例

入力 1

6 4
10 3
6 2
5 3
9 7
3 6
11 2

出力 1

2

注記

6頭の牛がおり、混み合うと感じる距離のしきい値は4です。牛1は位置 $x=10$、高さ $h=3,$ であり、他も同様です。

位置 $x=5$ と $x=6$ の牛はどちらも混み合っています。

問題作成者:Brian Dean, 2013

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.