QOJ.ac

QOJ

実行時間制限: 1.5 s メモリ制限: 256 MB 満点: 100

#5264. Overtaking

統計

Bajtazar is driving to the seaside in his new sports car. He is driving on a highway and, as befits a proper driver, he is moving in the right lane. However, there are $n$ trucks in front of him in the right lane that he will have to overtake.

The trucks are numbered from 1 to $n$, starting from the one closest to Bajtazar's car; the $i$-th truck moves at a speed $v_i$, has a length $d_i$, and is initially located at a distance $x_i$ in front of Bajtazar's car. For simplicity, we treat the vehicles as rectangles without edges, and their position is defined by their front side.

If, due to a difference in speeds, the front of the $i$-th truck catches up to the rear of the truck in front of it (the one numbered $i+1$), the $i$-th truck slows down to the speed of the $(i+1)$-th truck (i.e., the trucks do not overtake each other).

Bajtazar drives at a speed $V$, which is faster than any of the trucks ($V > v_i$ for every $i$), and his car has a length $D$. At the moment the front of his car catches up to the rear of any truck, Bajtazar immediately performs a lane change maneuver and continues driving in the left lane. As soon as it is possible to change back to the right lane, Bajtazar performs this maneuver (even if he would have to change back to the left lane at the same moment).

Bajtazar wonders how many times he will perform a lane change maneuver from the right to the left lane while overtaking all the trucks. We assume that there are no other vehicles on the highway at this time.

Input

The first line of the input contains four integers $n, D, W, M$ ($1 \le n \le 100\,000$, $1 \le D \le 10^9$, $1 \le W, M \le 1000$), representing the number of trucks, the length of Bajtazar's car, and his speed given by the formula $V = W/M$.

The next $n$ lines contain descriptions of the trucks; the $i$-th line contains four integers $x_i, d_i, w_i, m_i$ ($1 \le x_i, d_i \le 10^9$, $1 \le w_i, m_i \le 1000$). The speed of the truck is $v_i = w_i/m_i$.

The vehicles do not overlap, meaning $0 \le x_1 - d_1$ and $x_i \le x_{i+1} - d_{i+1}$ for $1 \le i < n$.

All lengths and positions are expressed in units of distance, and speeds in units of distance per unit of time.

Output

Your program should output a single line containing an integer representing how many times Bajtazar will perform a lane change maneuver to the left.

Examples

Input 1

3 1 1 1
3 2 1 4
6 3 1 2
10 2 1 4

Output 1

2

Note

Example explanation: Bajtazar's car moves at a speed of 1, and the trucks move at speeds $\frac{1}{4}, \frac{1}{2}$, and $\frac{1}{4}$. At time $1\frac{1}{3}$, Bajtazar reaches the first truck and changes to the left lane, and at time $5\frac{1}{3}$ he returns to the right lane. At time 6, he changes to the left lane for the second time. At time 8, the second truck reaches the third one and slows down to $\frac{1}{4}$. At time $14\frac{2}{3}$, Bajtazar returns to the right lane.

Subtasks

Subtask Additional Constraints Points
1 all $v_i$ are equal 10
2 the sequence $v_i$ is non-decreasing ($v_i \le v_{i+1}$) 20
3 $n \le 1000$ 35
4 no additional constraints 35

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.