The K-League
Time limit1sMemory limit128 MB
For each team, decide whether remaining games can end with no team holding more wins than it.
- Level
Hard8 of 10
- Topics
- Graph
- Solved
- No attempts yet
Problem
Supporters of the professional football clubs in the K-League wonder whether the team they cheer for can still win the championship. In other words, is it possible to decide the winners of all the remaining games so that no team finishes the season with more wins than ? Two or more teams may share the title.
You are given, for every team , its current number of wins and losses , and for every pair of teams and the number of games still to be played between them (where and is the number of teams). The teams are numbered . Find every team that still has a chance of winning the championship. There are no draws: every game has exactly one winner and one loser.
Input
The input contains several test cases. The first line gives the number of test cases .
Each test case consists of three lines:
- The first line has the number of teams ().
- The second line has integers , where and are the current wins and losses of team ; each is a nonnegative integer at most .
- The third line has integers , where is the number of remaining games between teams and ; each is a nonnegative integer at most . For all and , , and when .
Integers on the same line are separated by one or more spaces.
Output
For each test case print exactly one line. The line lists the numbers of all teams that still have a chance of winning the championship, in increasing order, separated by single spaces.