#E. [USACO13NOV] Crowded Cows S

    Type: RemoteJudge 1000ms 125MiB

[USACO13NOV] Crowded Cows S

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(i) and has height h(i) (1 <= x(i),h(i) <= 1,000,000,000).

A cow feels "crowded" if there is another cow at least twice her height within distance D on her left, and also another cow at least twice her height within distance D on her right (1 <= D <= 1,000,000,000). Since crowded cows produce less milk, Farmer John would like to count the number of such cows. Please help him.

FJ有 N(1N50000)N(1\le N\le50000) 头奶牛沿着一维的栅栏吃草,第 ii 头奶牛在目标点 xix_i ,它的身高是 hi(1xi,hi109)h_i (1 \le x_i,h_i\le10^9)

当一头奶牛左边 D(1D109)D(1\le D\le10^9) 距离内且右边 DD 距离内有身高至少是它的两倍的奶牛,它就会觉得拥挤。

请计算觉得拥挤的奶牛的数量。

输入格式

* Line 1: Two integers, N and D.

* Lines 2..1+N: Line i+1 contains the integers x(i) and h(i). The locations of all N cows are distinct.

第一行两个整数 N,DN,D

接下来 NN ,每行两个整数 xi,hix_i,h_i。保证 xix_i 互不相同。

输出格式

* Line 1: The number of crowded cows.

一行一个整数,表示觉得拥挤的奶牛的数量。

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

2 

提示

There are 6 cows, with a distance threshold of 4 for feeling crowded. Cow #1 lives at position x=10 and has height h=3, and so on.

The cows at positions x=5 and x=6 are both crowded.

初二竞赛组——单调队列

Not Claimed
Status
Done
Problem
6
Open Since
2024-9-11 9:00
Deadline
2024-9-26 23:59
Extension
24 hour(s)