English · Original
Chinese · Translation
Formal · Original
Arkady the air traffic controller is now working with _n_ planes in the air. All planes move along a straight coordinate axis with Arkady's station being at point 0 on it. The _i_\-th plane, small enough to be represented by a point, currently has a coordinate of _x__i_ and is moving with speed _v__i_. It's guaranteed that _x__i_·_v__i_ < 0, i.e., all planes are moving towards the station.
Occasionally, the planes are affected by winds. With a wind of speed _v__wind_ (not necessarily positive or integral), the speed of the _i_\-th plane becomes _v__i_ + _v__wind_.
According to weather report, the current wind has a steady speed falling inside the range \[ - _w_, _w_\] (inclusive), but the exact value cannot be measured accurately since this value is rather small — smaller than the absolute value of speed of any plane.
Each plane should contact Arkady at the exact moment it passes above his station. And you are to help Arkady count the number of pairs of planes (_i_, _j_) (_i_ < _j_) there are such that there is a possible value of wind speed, under which planes _i_ and _j_ contact Arkady at the same moment. This value needn't be the same across different pairs.
The wind speed is the same for all planes. You may assume that the wind has a steady speed and lasts arbitrarily long.
## Input
The first line contains two integers _n_ and _w_ (1 ≤ _n_ ≤ 100 000, 0 ≤ _w_ < 105) — the number of planes and the maximum wind speed.
The _i_\-th of the next _n_ lines contains two integers _x__i_ and _v__i_ (1 ≤ |_x__i_| ≤ 105, _w_ + 1 ≤ |_v__i_| ≤ 105, _x__i_·_v__i_ < 0) — the initial position and speed of the _i_\-th plane.
Planes are pairwise distinct, that is, no pair of (_i_, _j_) (_i_ < _j_) exists such that both _x__i_ = _x__j_ and _v__i_ = _v__j_.
## Output
Output a single integer — the number of unordered pairs of planes that can contact Arkady at the same moment.
[samples]
## Note
In the first example, the following 3 pairs of planes satisfy the requirements:
* **(2, 5)** passes the station at time 3 / 4 with _v__wind_ = 1;
* **(3, 4)** passes the station at time 2 / 5 with _v__wind_ = 1 / 2;
* **(3, 5)** passes the station at time 4 / 7 with _v__wind_ = - 1 / 4.
In the second example, each of the 3 planes with negative coordinates can form a valid pair with each of the other 3, totaling 9 pairs.
Arkady 是空中交通管制员,现在有 #cf_span[n] 架飞机在空中飞行。所有飞机沿着一条直线坐标轴飞行,Arkady 的站点位于该轴上的点 #cf_span[0]。第 #cf_span[i] 架飞机(可视为一个点)当前位于坐标 #cf_span[xi],并以速度 #cf_span[vi] 移动。保证 #cf_span[xi·vi < 0],即所有飞机均朝向站点飞行。
偶尔,飞机受风的影响。当风速为 #cf_span[vwind](不一定是正数或整数)时,第 #cf_span[i] 架飞机的速度变为 #cf_span[vi + vwind]。
根据天气报告,当前风速稳定且位于区间 #cf_span[[ - w, w]](含端点)内,但由于该值较小——小于任何飞机速度的绝对值——因此无法精确测量。
每架飞机应在恰好经过 Arkady 站点的时刻与其联系。你需要帮助 Arkady 计算满足以下条件的无序飞机对 #cf_span[(i, j)](#cf_span[i < j])的数量:存在某个风速值,使得飞机 #cf_span[i] 和 #cf_span[j] 在同一时刻与 Arkady 联系。不同对的风速值可以不同。
风速对所有飞机相同。你可以假设风速恒定且持续时间任意长。
第一行包含两个整数 #cf_span[n] 和 #cf_span[w](#cf_span[1 ≤ n ≤ 100 000],#cf_span[0 ≤ w < 105])——飞机数量和最大风速。
接下来的 #cf_span[n] 行中,第 #cf_span[i] 行包含两个整数 #cf_span[xi] 和 #cf_span[vi](#cf_span[1 ≤ |xi| ≤ 105],#cf_span[w + 1 ≤ |vi| ≤ 105],#cf_span[xi·vi < 0])——第 #cf_span[i] 架飞机的初始位置和速度。
所有飞机互不相同,即不存在任何一对 #cf_span[(i, j)](#cf_span[i < j])使得 #cf_span[xi = xj] 且 #cf_span[vi = vj] 同时成立。
请输出一个整数——能够同时与 Arkady 联系的无序飞机对的数量。
## Input
第一行包含两个整数 #cf_span[n] 和 #cf_span[w](#cf_span[1 ≤ n ≤ 100 000],#cf_span[0 ≤ w < 105])——飞机数量和最大风速。接下来的 #cf_span[n] 行中,第 #cf_span[i] 行包含两个整数 #cf_span[xi] 和 #cf_span[vi](#cf_span[1 ≤ |xi| ≤ 105],#cf_span[w + 1 ≤ |vi| ≤ 105],#cf_span[xi·vi < 0])——第 #cf_span[i] 架飞机的初始位置和速度。所有飞机互不相同,即不存在任何一对 #cf_span[(i, j)](#cf_span[i < j])使得 #cf_span[xi = xj] 且 #cf_span[vi = vj] 同时成立。
## Output
请输出一个整数——能够同时与 Arkady 联系的无序飞机对的数量。
[samples]
## Note
在第一个例子中,以下 #cf_span[3] 对飞机满足要求:
*#cf_span[(2, 5)]* 在风速 #cf_span[vwind = 1] 时于时间 #cf_span[3 / 4] 经过站点;
*#cf_span[(3, 4)]* 在风速 #cf_span[vwind = 1 / 2] 时于时间 #cf_span[2 / 5] 经过站点;
*#cf_span[(3, 5)]* 在风速 #cf_span[vwind = - 1 / 4] 时于时间 #cf_span[4 / 7] 经过站点。
在第二个例子中,三个坐标为负的飞机中的每一个都可以与其余三个中的每一个组成有效对,总计 #cf_span[9] 对。
Let $ n $ be the number of planes, and $ w \geq 0 $ the maximum wind speed magnitude.
For each plane $ i $, let:
- $ x_i \in \mathbb{R} \setminus \{0\} $ be its initial position,
- $ v_i \in \mathbb{R} \setminus \{0\} $ be its initial speed,
with the constraint $ x_i \cdot v_i < 0 $, meaning all planes are moving toward the origin (Arkady’s station at 0).
A wind of speed $ v_{\text{wind}} \in [-w, w] $ affects all planes uniformly: the new speed of plane $ i $ becomes $ v_i + v_{\text{wind}} $.
The time for plane $ i $ to reach the station under wind $ v_{\text{wind}} $ is:
$$
t_i(v_{\text{wind}}) = \frac{-x_i}{v_i + v_{\text{wind}}}
$$
(since $ x_i \cdot v_i < 0 $, the denominator is nonzero and the sign ensures $ t_i > 0 $).
We seek the number of unordered pairs $ (i, j) $ with $ i < j $ such that there exists some $ v_{\text{wind}} \in [-w, w] $ for which:
$$
t_i(v_{\text{wind}}) = t_j(v_{\text{wind}})
\quad \iff \quad
\frac{-x_i}{v_i + v_{\text{wind}}} = \frac{-x_j}{v_j + v_{\text{wind}}}
$$
Simplifying:
$$
\frac{x_i}{v_i + v_{\text{wind}}} = \frac{x_j}{v_j + v_{\text{wind}}}
\quad \iff \quad
x_i (v_j + v_{\text{wind}}) = x_j (v_i + v_{\text{wind}})
$$
Expanding:
$$
x_i v_j + x_i v_{\text{wind}} = x_j v_i + x_j v_{\text{wind}}
\quad \iff \quad
(x_i - x_j) v_{\text{wind}} = x_j v_i - x_i v_j
$$
Thus, if $ x_i \ne x_j $, we solve for $ v_{\text{wind}} $:
$$
v_{\text{wind}} = \frac{x_j v_i - x_i v_j}{x_i - x_j}
$$
Let:
$$
v_{\text{req}}^{(i,j)} = \frac{x_j v_i - x_i v_j}{x_i - x_j}
$$
Then, the pair $ (i, j) $ satisfies the condition **if and only if**:
$$
v_{\text{req}}^{(i,j)} \in [-w, w]
$$
Note: The condition $ x_i \cdot v_i < 0 $ ensures that denominators are never zero in the original time expressions, and $ x_i \ne x_j $ for distinct planes (as per "pairwise distinct" — though even if $ x_i = x_j $, since $ v_i \ne v_j $, the times would differ unless wind adjusts them, but the problem states no two planes have both same $ x $ and same $ v $, so $ x_i = x_j \Rightarrow v_i \ne v_j $, and then $ v_{\text{req}} $ is undefined unless $ x_i = x_j $ and $ v_i = v_j $, which is forbidden). So we may assume $ x_i \ne x_j $ always.
Thus, the problem reduces to:
> Count the number of unordered pairs $ (i, j) $, $ i < j $, such that
> $$
> \left| \frac{x_j v_i - x_i v_j}{x_i - x_j} \right| \leq w
> $$
This is the final mathematical formulation.
API Response (JSON)
{
"problem": {
"name": "D. Contact ATC",
"description": {
"content": "Arkady the air traffic controller is now working with _n_ planes in the air. All planes move along a straight coordinate axis with Arkady's station being at point 0 on it. The _i_\\-th plane, small eno",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 1000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF924D"
},
"statements": [
{
"statement_type": "Markdown",
"content": "Arkady the air traffic controller is now working with _n_ planes in the air. All planes move along a straight coordinate axis with Arkady's station being at point 0 on it. The _i_\\-th plane, small eno...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "Arkady 是空中交通管制员,现在有 #cf_span[n] 架飞机在空中飞行。所有飞机沿着一条直线坐标轴飞行,Arkady 的站点位于该轴上的点 #cf_span[0]。第 #cf_span[i] 架飞机(可视为一个点)当前位于坐标 #cf_span[xi],并以速度 #cf_span[vi] 移动。保证 #cf_span[xi·vi < 0],即所有飞机均朝向站点飞行。\n\n偶尔,飞机受风的影...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "Let $ n $ be the number of planes, and $ w \\geq 0 $ the maximum wind speed magnitude.\n\nFor each plane $ i $, let:\n- $ x_i \\in \\mathbb{R} \\setminus \\{0\\} $ be its initial position,\n- $ v_i \\in \\mathbb{...",
"is_translate": false,
"language": "Formal"
}
]
}