Assign Taekhee's cards to rounds and pick a strength-joker round so that Namgyu's best-case score (over his joker round) is minimized, ties broken lexicographically.
Hard8GreedySortingBrute forceImplementationNo attempts yetTime limit1sMemory limit128 MBSpacetime Stone is a card game for two players.
Each player receives N cards. Every card carries one strength value and one intelligence value. Once the game starts, both players put down one card per round. The player whose card has the larger sum of strength and intelligence scores 1 point, and both cards played are discarded. After N rounds, the player with more points wins.
Taekhee played this game for 12000 hours, got bored of it, and added one rule. On top of the N cards, each player starts with one joker card. There are two kinds of joker, the strength joker and the intelligence joker. Before the game starts, each player fixes the round in which the joker takes effect, and neither player lets the other know. A player cannot decline to use the joker.
From the moment the round with the joker begins, and until the game ends or another joker takes effect, rounds are decided this way.
If both players pick the same round, only the intelligence joker takes effect from that round on.
Taekhee wondered how the jokers affect the balance, so he set up a practice match against Namgyu, who also has 12000 hours of playtime. Taekhee starts with the strength joker and Namgyu with the intelligence joker.
Suppose a game with N equal to 6 goes as follows. (a, b) is a card with strength a and intelligence b.
| Round | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Namgyu | (5, 10) | (1, 18) | (10, 1) | (30, 30) | (5, 100) | (21, 23) |
| Taekhee | (11, 7) | (15, 15) | (2, 2) | (2, 7) | (13, 19) | (33, 40) |
| Value compared | strength + intelligence | intelligence | intelligence | intelligence | strength | strength |
Namgyu decided to use the intelligence joker from round 2, and Taekhee decided to use the strength joker from round 5. Round 1 is free of any joker, so Taekhee wins it with the larger sum and scores 1 point. Rounds 2 to 4 go to the larger intelligence, which gives Taekhee 1 point and Namgyu 2 points. Rounds 5 and 6 go to the larger strength, and Taekhee takes 2 points. The final score is 4 for Taekhee and 2 for Namgyu. The table only shows how scoring works. It is not the best choice for Taekhee.
A practice match is still a match. Taekhee did not want to lose to Namgyu, so he found out in advance the order in which Namgyu plays his cards. He still does not know which round Namgyu uses the intelligence joker in, so he settled on a simple strategy. He assumes Namgyu picks the round that is worst for Namgyu, and he makes the score Namgyu gets in that case as small as possible.
The cards Namgyu plays over the N rounds are given in order, and the N cards Taekhee holds are given. Choose the round in which Taekhee triggers the strength joker and the order in which he plays his cards, and make Namgyu's score as small as possible when the game goes as badly as possible for Namgyu (that is, as well as possible for Taekhee).
The first line contains the number of cards N. (1 ≤ N ≤ 50)
Each of the next N lines contains the strength P and the intelligence W of the card Namgyu plays in round i, for the i-th of those lines. (1 ≤ P, W ≤ 10^9)
Each of the following N lines contains the strength P and the intelligence W of a card Taekhee holds. (1 ≤ P, W ≤ 10^9)
For every card A of Namgyu and every card B of Taekhee, the strengths differ, the intelligences differ, and the sums of strength and intelligence differ. No round ends in a draw.
On the first line, print the number of the round in which Taekhee triggers the strength joker. The number is between 1 and N.
On the second line, print the order in which Taekhee plays his cards as N integers separated by spaces. Cards are numbered 1 to N in the order given in the input.
If several answers satisfy the conditions, print the lexicographically smallest output. Take the answer whose round number on the first line is smallest, and among those, take the answer whose second line is lexicographically smallest.