Gahee and Process 2
Time limit3.5sMemory limit512 MB
Given n processes with id, remaining time, and priority, find which process id the scheduler runs at second T for each query.
- Level
Medium7 of 10
- Topics
- Binary search, Sorting, Math
- Solved
- No attempts yet
Problem
Gahee was assigned to implement a scheduler. The criteria for choosing the process to run are as follows.
- The process with the largest priority value.
- If several processes share the largest priority value, the process with the smallest .
The scheduler Gahee wrote runs with the following algorithm.
- Choose the process to run according to the criteria. Let be the of the chosen process. Run the process with .
- After 1 second, the priority of every process except the one with equal to increases by 1. The time needed to finish the process with equal to decreases by 1.
- If any process still has remaining execution time, return to step 1. Otherwise, stop.
Only one process runs at a time. At second 1, the scheduler runs the process it chose first. Gahee wants to know which process the scheduler selects at second . Please help Gahee.
Input
The first line contains and .
The next lines, from line 2 to line , each contain , , and separated by spaces. This means the -th process has equal to , needs seconds to finish, and has initial priority .
From line to line , each query is given as follows.
is a query asking which process the scheduler selects at second .
Output
Print the answer to each of the queries on its own line.
Constraints
- Each is at least 1 and at most the smaller of and the total time needed to finish all processes.