Fakes and Shidget
Time limit2sMemory limit512 MB
Each of n characters offers two quests with given times and rewards; find the maximum long-run gold per minute when the character each round is chosen uniformly at random.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
Pavel loves the game Fakes and Shidget very much. The game literally consists of the following process. The player uniformly randomly meets one of characters. Every character offers the player to choose one of two quests. The first quest of the -th character requires minutes to complete and brings gold, and the second quest requires minutes and brings gold. The player chooses one of these quests, completes it and immediately meets another random character, and so on.
Pavel will play this game infinitely long. How fast can he earn gold if he will play optimally?
More formally, let is the time Pavel plays this game, and is the amount of gold he earns for the time . You should find the limit .
Input
The first line contains an integer () --- the number of characters in the game.
Each of the next lines contains four integers , , and () --- the duration of the first quest, the reward for the first quest, the duration of the second quest, the reward for the second quest of the -th character.
Output
Output one floating point number --- the maximal possible speed of earning gold.
The absolute or relative error of the answer shouldn't exceed .