Dollars and Euros
Time limit1sMemory limit128 MB
Select n of 2n-1 wallets with the fixed dollar-sorted rule so dollars and euros each reach half the totals.
- Level
Medium4 of 10
- Topics
- Sorting, Simulation
- Solved
- No attempts yet
Problem
Wallace is a well known gangster, a real G. Like every gangster he has a lot of cash that he likes to spend on jewels. For safety he does not keep his money in a single wallet, but spreads it across many. Wallace is about to head out on the town with his crew.
He wants to take roughly half of his wallets, yet he also wants to carry enough money. More precisely, Wallace has wallets, and each one holds some number of dollars and some number of euros. For the trip he wants to take exactly wallets so that the total number of dollars in these wallets is at least half of the total dollars across all wallets, and the total number of euros in the chosen wallets is at least half of the total euros across all wallets.
Wallace knows how to make money; you know how to program. You know what to do.
Input
The first line of the input contains a single integer , the number of test sets. The description of each test set follows.
The first line of a test set contains a single integer (), meaning that Wallace has wallets. Each of the next lines describes one wallet with two integers and (): wallet holds dollars and euros.
You may assume that the sum of over all test sets does not exceed .
Output
Print the answer for each test set in order.
It can be shown that a valid choice of wallets always exists. To make the answer unique, assume that Wallace picks his wallets with the following fixed procedure.
- Number the wallets in the order they are given.
- Sort the wallets by their dollar amount in decreasing order; break ties by euro amount in decreasing order, and break any remaining ties by wallet number in increasing order.
- Keep the first wallet in this order.
- Group the remaining wallets, in the same order, into consecutive pairs (the 2nd with the 3rd, the 4th with the 5th, and so on). From each pair keep the wallet with more euros; if the two hold equal euros, keep the one with more dollars; if they are still equal, keep the one with the smaller wallet number.
This selects exactly wallets and always satisfies both conditions.
For each test set print two lines. On the first line print Yo. On the second line print the chosen wallet numbers in increasing order, separated by single spaces.