Favourite Dish
Time limit4sMemory limit1024 MB
For each weight pair, find the dish whose weighted sum of taste and plating scores is largest, breaking ties by the smallest dish number.
- Level
Medium6 of 10
- Topics
- Geometry, Binary search, Sorting
- Solved
- No attempts yet
Problem
France is a country of gastronomy. For a dish, both the taste and the plating matter. Still, when different people evaluate a dish, some focus more on taste and others focus more on plating. The Olympic Village dining hall serves dishes, numbered from to . Each dish has a score for taste and a score for plating. There are also persons, numbered from to . Each person has a weight for taste and a weight for plating. A person's final score for a dish is the weighted average of the dish's taste and plating scores.
The chefs want to give everyone their favourite dish on the evening of the closing ceremony. Find the favourite dish of each person. If several dishes tie for the highest score, choose the one with the smallest number.
Input
Each line contains two space-separated integers. The first line contains and . The next lines follow, where the th line contains and , the taste and plating scores of dish . The next lines follow, where the th line contains and , the taste and plating weights of person .
Output
Output lines. The th line contains one number, the number of the favourite dish of person .
Constraints
- , , and for all
- , , and for all
- the pairs are pairwise distinct
- the pairs are pairwise distinct