University Entrance Examination
Time limit1sMemory limit128 MB
Given students with scores, home regions, and program preference lists, plus program capacities, assign students to programs under a local-region priority rule and a fairness rule.
- Level
Hard8 of 10
- Topics
- Implementation, Greedy, Sorting, Simulation
- Solved
- No attempts yet
Problem
Every year a huge number of high-school graduates compete for a limited number of university places through a single, centralized national entrance examination, run by the Education Evaluation Organization (EEO). After the exam, each eligible participant submits a priority list of the Field-Department-University programs (FDUs) they want to join, ordered from most to least preferred. Using each participant's total score, their priority list, and the selection rules below, the EEO fills every FDU up to its capacity. One selection goal is to encourage students to attend universities near their home region, which reduces demand for dormitories. Each accepted participant is placed in exactly one FDU; anyone not placed in any FDU on their list has failed.
You are given students and programs . Each student has a total score, a home geographic region (the region where their high-school diploma was awarded), and a priority list of the programs they want. Each program has a geographic region (where its university is located) and a capacity for the year.
Assign students to programs so that both rules below hold.
- Local-student rule. Consider two students and who both listed a program located in region , and suppose . If is local to (its home region is ), is non-local (home region other than ), and , then has priority over for . In every other case has priority over for .
- Fairness rule. Each accepted student is placed in the earliest program on their own priority list that they can actually enter.
All scores are distinct integers.
Input
The first line contains an integer (), the number of test cases. Each test case is given as follows.
The first line contains two integers () and ().
Each of the next lines describes one student in the form , where is the student's home region number, is their exam score, () is the length of their priority list, and are the program numbers in order of preference.
Each of the next lines describes one program as two integers and : the region number of and its capacity.
Region numbers are arbitrary integers.
Output
For each test case, print lines, one per student in input order. On the -th line print if student is accepted into program , or not accepted if the student is not admitted to any program on their list.
Print exactly one blank line between the outputs of consecutive test cases.