Watermelons of the Field of Wonders
Time limit2sMemory limit256 MB
Given N lines W0 + S*K, report the line with the largest value at each of M query days, breaking ties by smallest index.
- Level
Medium7 of 10
- Topics
- Segment tree, Sorting, Binary search
- Solved
- No attempts yet
Problem
The world financial crisis broke the economy of the Land of Fools, so Buratino started growing watermelons for extra income. He runs the business on the famous Field of Wonders, of course. Whether it is his diligence or the odd nature of the field, each watermelon grows at its own speed, and that speed never changes over time. The watermelons of the Field of Wonders soon became famous and tourists came for them.
When Buratino noticed that tourists like photos with watermelons, he opened one more service for VIP tourists: a photo with the heaviest watermelon.
One day he measured the weight and the growth speed of every watermelon at the same time. On the day days after that, a watermelon weighs , where is the weight he measured and is the growth speed of that watermelon.
Buratino does not want to redo this arithmetic by hand every day. Write a program that finds the heaviest watermelon on a given day.
Input
The first line contains the number of watermelons . () Each of the next lines contains the initial weight and the growth speed of one watermelon, separated by a single space. ()
The next line contains the number of days you have to answer for. () Each of the last lines contains one day number . ()
Output
Print lines, one per day, in the same order as the input. On each line print the number of the heaviest watermelon on that day. When several watermelons are the heaviest, print the smallest of their numbers. The watermelons are numbered from to in the order they appear in the input.