# P3088 [USACO13NOV]挤奶牛Crowded Cows

• 512通过
• 1.2K提交
• 题目提供者 FarmerJohn2
• 评测方式 云端评测
• 标签 单调队列 概率论,统计 队列 USACO 2013 高性能
• 难度 普及+/提高
• 时空限制 1000ms / 128MB
• 提示：收藏到任务计划后，可在首页查看。

## 题目描述

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(1 <= N <= 50,000)头奶牛沿着一维的栅栏吃草，第i头奶牛在目标点x(i) ，它的身高是 h(i) (1 <=x(i),h(i) <= 1,000,000,000)。

当一头奶牛左边D距离内而且右边D距离内有身高至少是它的两倍的奶牛，t (1 <= D <= 1,000,000,000)，它就会觉得拥挤。

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

## 输入输出格式

输入格式：

* 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.

输出格式：

* Line 1: The number of crowded cows.

## 输入输出样例

输入样例#1： 复制
6 4
10 3
6 2
5 3
9 7
3 6
11 2

输出样例#1： 复制
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.

提示
标程仅供做题后或实在无思路时参考。
请自觉、自律地使用该功能并请对自己的学习负责。
如果发现恶意抄袭标程，将按照I类违反进行处理。