Bar "Duck"
InterviewTime limit5sMemory limit256 MB
Trash pieces on a table of length L must be flung off within T seconds using at most E energy; find the longest clean gap that can be made.
- Level
Medium5 of 10
- Topics
- Two pointers, Array
- Solved
- No attempts yet
Problem
You're having a party at your place tonight! Some of your friends will come over, and you're going to spend the evening playing your favourite board game called 'Bar "Duck"'. But several minutes before the guests arrive, you discover that the only table suitable for playing is covered with trash of mysterious origin. You have no time for proper cleaning, so you will fling some of the trash pieces away so that at least part of the table is clean.
The table is long but very narrow, so its surface can be represented as a straight segment of length centimeters. The coordinate system is chosen so that one end of the table has coordinate 0 and the other end has coordinate . There are pieces of trash on the table. The -th piece is at coordinate and has mass grams.
You can fling any of the pieces, that is, give them an initial speed in either of the two directions along the axis. After a piece is flung, it moves at its initial speed with no acceleration or deceleration until it reaches an end of the table and falls to the floor. Pieces move independently and do not collide or interfere with each other. Applying a force costs energy: to make an object of mass grams move at speed centimeters per second, you must spend units of energy.
The game starts exactly seconds from now. The game needs a lot of space, so at the start you will choose the longest segment of the table that contains no trash. You are tired after your day job, so you will not spend more than units of energy on flinging. You may give any speed to any piece, choosing each piece's speed independently, as long as the total energy does not exceed .
Find the length of the longest clean segment of the table you can obtain after seconds, spending no more than units of energy.
Input
The first line contains four space-separated integers , , , and (, ).
The next lines describe the trash pieces. The -th line contains two space-separated integers and (, ), the position and mass of the -th piece. No two pieces occupy the same place, and the pieces are sorted by increasing .
Output
Print one real number, the length (in centimeters) of the longest clean table segment you can obtain after seconds while spending no more than units of energy. The answer is judged correct if its relative or absolute error compared to the jury's answer does not exceed .
Hint
In the first test, we spend all energy to give the only piece a speed of centimeters per second, so after one second the longest clean segment has length centimeters.
In the second test, the optimal way is to make both pieces move at a speed of 1 centimeter per second in opposite directions.