Favourite dish

시간 제한4초메모리 제한1024 MB

요약
각 사람마다 (맛, 플레이팅) 점수와 가중치의 내적을 최대로 하는 접시를 찾고, 동점이면 번호가 가장 작은 접시를 고른다.
난이도

어려움10점 중 8점

유형
기하, 정렬, 이분 탐색
정답자
아직 제출이 없습니다

문제

France is a country of gastronomy. For a dish, both the taste and plating are important. Nevertheless, when different people evaluate a dish, some focus more on taste and some focus more on plating. At the Olympic Village dining hall, there are NN dishes, numbered from 11 to NN; each dish has a score on its taste and a score on its plating. There are also MM persons, numbered from 11 to MM; each person has a weight on taste and a weight on plating. One person’s final score of a dish is the weighted average of the dish’s scores on taste and plating.

The chefs at the Olympics want to provide everyone with their favourite dish on the evening of the closing ceremony. Your task is to calculate everyone’s favourite dish. If multiple dishes tie for the highest score as a person’s favourite, choose the one with the smallest number.

입력

Each line contains two space-separated integers. The first line contains the numbers NN and MM. Then follow NN lines; the kkth such line contains two integers t_kt\_k and p_kp\_k, which are the scores of the dish kk on taste and on plating. Then come MM more lines; the ℓ\ellth such line contains two integers T_ℓT\_\ell and P_ℓP\_\ell, which are the weights of person ℓ\ell on taste and on plating.

출력

The output should contain MM lines. The ℓ\ellth such line should contain one number: the number of the favourite dish of person ℓ\ell.

제한

  • 1≤N≤500,0001 \le N \le 500\\, 000
  • 1≤M≤500,0001 \le M \le 500\\, 000
  • 0≤t_k≤1,000,0000 \le t\_k \le 1\\, 000\\, 000, 0≤p_k≤1,000,0000 \le p\_k \le 1\\, 000\\, 000, and (t_k,p_k)≠(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 (t_k,p_k)(t\_k , p\_k) are pairwise distinct
  • the MM pairs (T_ℓ,P_ℓ)(T\_\ell , P\_\ell) are pairwise distinct

예제2

  1. 예제 1

    입력
    4 3
    2 5
    3 4
    4 2
    1 6
    6 4
    2 8
    5 5
    
    예상 출력
    2
    4
    1
    
  2. 예제 2

    입력
    3 4
    1 0
    0 2
    0 1
    1 1
    2 2
    2 1
    1 0
    
    예상 출력
    2
    2
    1
    1