Under construction

Still being built. Things may change

Favourite Dish

Time limit4sMemory limit1024 MB

Summary
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 NN dishes, numbered from 11 to NN. Each dish has a score for taste and a score for plating. There are also MM persons, numbered from 11 to MM. 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 NN and MM. The next NN lines follow, where the kkth line contains tkt_k and pkp_k, the taste and plating scores of dish kk. The next MM lines follow, where the ℓ\ellth line contains TℓT_\ell and PℓP_\ell, the taste and plating weights of person ℓ\ell.

Output

Output MM lines. The ℓ\ellth line contains one number, the number of the favourite dish of person ℓ\ell.

Constraints

  • 1≤N≤500 0001 \le N \le 500\,000
  • 1≤M≤500 0001 \le M \le 500\,000
  • 0≤tk≤1 000 0000 \le t_k \le 1\,000\,000, 0≤pk≤1 000 0000 \le p_k \le 1\,000\,000, and (tk,pk)≠(0,0)(t_k, p_k) \ne (0, 0) for all k≤Nk \le N
  • 0≤Tℓ≤1 000 0000 \le T_\ell \le 1\,000\,000, 0≤Pℓ≤1 000 0000 \le P_\ell \le 1\,000\,000, and (Tℓ,Pℓ)≠(0,0)(T_\ell, P_\ell) \ne (0, 0) for all ℓ≤M\ell \le M
  • the NN pairs (tk,pk)(t_k, p_k) are pairwise distinct
  • the MM pairs (Tℓ,Pℓ)(T_\ell, P_\ell) are pairwise distinct

Examples2

  1. Example 1

    Input
    4 3
    2 5
    3 4
    4 2
    1 6
    6 4
    2 8
    5 5
    
    Expected output
    2
    4
    1
    
  2. Example 2

    Input
    3 4
    1 0
    0 2
    0 1
    1 1
    2 2
    2 1
    1 0
    
    Expected output
    2
    2
    1
    1