Cowmpetency
Time limit2sMemory limit1024 MB
Fill the forgotten scores so the sequence is lexicographically smallest and each (a, h) pair makes cow h the first to beat cows 1 through a, or print -1.
- Level
Medium6 of 10
- Topics
- Array, Greedy, Implementation
- Solved
- No attempts yet
Problem
Farmer John is hiring a new herd leader for his cows. To that end, he has interviewed () cows for the position. After interviewing the th candidate, he assigned the candidate an integer "cowmpetency" score ranging from to inclusive () that is correlated with their leadership abilities.
Because he has interviewed so many cows, Farmer John does not remember all of their cowmpetency scores. However, he does remember () pairs of numbers where cow was the first cow with a strictly greater cowmpetency score than cows through (so ).
Farmer John now tells you the sequence (where means that he has forgotten cow 's cowmpetency score) and the pairs of . Help him determine the lexicographically smallest sequence of cowmpetency scores consistent with this information, or that no such sequence exists! A sequence of scores is lexicographically smaller than another if it assigns a smaller score to the first cow at which the two sequences differ.
Input
The first line contains , the number of independent test cases (). Each test case is described as follows:
- A line containing , , and .
- A line containing the sequence ().
- lines each containing a pair . All within a test case are distinct.
The sum of across all test cases does not exceed .
Output
For each test case, output a single line containing the lexicographically smallest sequence of cowmpetency scores consistent with the information, or if no such sequence exists.