GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday, 14 May 2022

[Solution] Saving the Jelly Solution Round 2 2022 - Code Jam 2022

Problem

Mr. Jolly teaches football (or soccer, for US speakers) to N children numbered from 1 to N. 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

Solution Click Below:-  CLICK HERE

 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.

Illustration of Sample Case #2.


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 N children on the field, and N+1 sweets. The sweets are numbered from 1 to N, with sweet 1 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, TT test cases follow. Each test begins with a line containing a single integer, N, the number of children on the field. The next N lines describe the positions of the children. Each of these lines contains two integers, Xi and Yi, representing the position of the i⁠-th child after the game ends. Then there are N+1 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, Xj and Yj, representing the position of the j⁠-th sweet.

Output

For each test case, output one line containing Case #xy, where x is the test case number (starting from 1) and y 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, y is POSSIBLE. If Mr. Jolly can save his jelly, output N additional lines representing the order the children will go and which jellies they will pick. The i⁠-th line should contain two integers Ai and Bi representing that child Ai will go next and will pick sweet Bi. The sweet Bi must be the closest (or tied for the closest) sweet to child Ai when they go to pick their sweet.

Limits

Memory limit: 1 GB.
1T100.
109Xi109, for all i.
109Yi109, for all i.
109Xj109, for all j.
109Yj109, for all j.

Test Set 1 (Visible Verdict)

Time limit: 10 seconds.
1N10.

Test Set 2 (Hidden Verdict)

Time limit: 45 seconds.
1N1000.

No comments:

Post a Comment