Chotu and Candy

5

3 votes
Very-Easy
Problem

Chotu has N candies, with each candy having 3 attributes - an ID, a sweetness value and a cost. Chotu will eat only one candy on a particular day. On any day, Chotu will eat the candy which has the highest sweetness value among all the candies present with him. If two candies have the same sweetness value, then Chotu selects the one with the lesser cost. If there is still a tie, then he selects the candy with the least ID (Note that id is unique for each candy).

Now, Chotu asks you Q queries, each containing a single integer X between 1 and N, you need to tell the day on which Chotu will eat the candy with ID X.

Input
First line contains two integers, N and Q denoting number of candies and number of queries.
Next N lines contains 3 space separated integers X, S, C, denoting the ID of the candy, its sweetness and its cost.
Next Q lines contains a single integer X.

Output
For each of the queries, print the day on which chotu will eat the given candy.

Constraints
1 <= N,Q <= 105
1 <= X <= 105
1 <= S,C <= 108
Value of X will be distinct.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Since the sweetness value of candy with ID 2 is highest so Chotu will eat it on day 1.
Candy 1, 3 and 4 have same sweetness but candy one has lower cost, so it will be eaten on day 2.
Candy 3 and 4 have same sweetness and cost, but candy 3 has lower ID, so it will be eaten on day 3.
Remaining candy 4 will be eaten on day 4.

Editor Image

?