[Solution] Saving the Jelly Solution Round 2 2022 - Code Jam 2022
Problem
Mr. Jolly teaches football (or soccer, for US speakers) to children numbered from to . He has taken to leaving sweets on the field where the games take place, one for each child. After the game is finished, each child can grab and eat one sweet as their reward.
The children are tired after games, so each child wants to grab the sweet closest to them. This could lead to fights — if the same sweet is closest to two or more children. To avoid that, after the game all the children stop where they are, and Mr. Jolly calls out their names, one by one. When a child's name is
called, they grab the closest sweet to them (out of the ones that weren't already grabbed, of course). In the case where two or more sweets are tied for the smallest distance, Mr. Jolly can decide which one the child grabs.
This has worked very well for Mr. Jolly for a while now, but today disaster struck! While laying out the sweets, Mr. Jolly accidentally dropped his blueberry jelly that he planned to eat after all the children go home. So now there are children on the field, and sweets. The sweets are numbered from to , with sweet being Mr. Jolly's blueberry jelly. Is there a way for Mr. Jolly to save his blueberry jelly by calling the children's names in such an order that the blueberry jelly is the one sweet left over?
Input
The first line of the input gives the number of test cases, . test cases follow. Each test begins with a line containing a single integer, , the number of children on the field. The next lines describe the positions of the children. Each of these lines contains two integers, and , representing the position of the -th child after the game ends. Then there are more lines that describe the positions of sweets after the game, where the first of the sweets is Mr. Jolly's blueberry jelly. Each of these lines contains two integers, and , representing the position of the -th sweet.
Output
For each test case, output one line containing Case #:
, where is the test case number (starting from 1) and is IMPOSSIBLE
if there is no way Mr. Jolly can choose the children (and break ties for the closest sweet) to leave his blueberry jelly uneaten. Otherwise, if Mr. Jolly can save his blueberry jelly, is POSSIBLE
. If Mr. Jolly can save his jelly, output additional lines representing the order the children will go and which jellies they will pick. The -th line should contain two integers and representing that child will go next and will pick sweet . The sweet must be the closest (or tied for the closest) sweet to child when they go to pick their sweet.
Limits
Memory limit: 1 GB.
.
, for all .
, for all .
, for all .
, for all .
Test Set 1 (Visible Verdict)
Time limit: 10 seconds.
.
Test Set 2 (Hidden Verdict)
Time limit: 45 seconds.
.
No comments:
Post a Comment