Start of the Pilgrimage
Time limit3sMemory limit1024 MB
After each item is added, find the largest ratio of total divine power to total weight over any eight of the items collected so far.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Sorting
- Solved
- No attempts yet
Problem
He has finally decided to become a pilgrim, and he is gradually gathering sacred items to prepare for the start of the pilgrimage. God has said that a pilgrim must carry eight distinct sacred items at all times during the journey.
Each sacred item carries divine power that keeps the pilgrim from tiring on the journey. Each item also has weight, and if it is too heavy, it is hard to carry. Let the divine powers of the eight chosen items be , and their weights be . Then the journey becomes easier by .
The items are given in the order he collected them. Each time an item is added, find the maximum ease of the journey when exactly eight of the items he holds are chosen.
Input
The first line contains a natural number , the number of sacred items collected. On each of the next lines, the -th line contains a natural number , the divine power of the -th item collected, and a natural number , its weight ().
Output
Print lines. On the -th line, print the maximum ease of the journey when eight items are chosen after items have been collected. An answer is accepted if its absolute or relative error is at most .