## [Solution] I, O Bot Solution Round 2 2022 - Code Jam 2022

### Problem

To welcome attendees to a developers' conference on Jupiter's moon of Io, the organizers inflated many giant beach balls. Each ball is in roughly the shape of either a or a , since those look sort of like the letters I and O. The conference just ended, and so now the beach balls need to be cleaned up. Luckily, the beach ball cleanup robot, BALL-E, is on the job!

The conference was held on an infinite horizontal line, with station in the middle, stations to the right, and stations to the left. Station 0 contains the conference's only beach ball storage warehouse. Each other station contains at most one beach ball.

BALL-E has two storage compartments, each of which can hold a single beach ball. One compartment can only hold -shaped balls and the other can only hold -shaped balls. (The -shaped balls are more oblong than the -shaped balls, so neither shape of ball will fit in the other shape's compartment.)

**Solution Click Below:-**

**CLICK HERE**

BALL-E initially has both the and compartments empty, and it starts off at station . The robot can do the following things:

- Move left one station or right one station. This costs 1 unit of power.
- If there is a ball at the current station, and BALL-E is not already storing a ball of that shape, it can put the ball in the appropriate compartment. This takes 0 units of power.
- If there is a ball at the current station, BALL-E can compress it so that its shape becomes the other shape. That is, a -shaped ball becomes a -shaped ball, or vice versa. It takes units of power to do this. Note that BALL-E may not change the shape of a ball that it has already put into one of its compartments.

- If BALL-E is at station 0 and is storing at least one ball, it can deposit all balls from its compartment(s) into the beach ball storage warehouse. This takes 0 units of power and leaves both compartments empty.

Notice that if BALL-E moves to a station and there is a ball there, BALL-E is not required to pick it up immediately, even if the robot has an open compartment for it. Also, if BALL-E moves to the station with the warehouse, it is not required to deposit any balls it has.

Find the minimum number of units of power needed for BALL-E to transfer all of the balls to the warehouse, using only the moves described above.

### Input

The first line of the input gives the number of test cases, . test cases follow.

The first line of each test case contains two integers, and : the number of balls and the amount of power units needed to change the shape of a ball, respectively.

The next lines describe the positions (i.e., station numbers) and the shapes of the balls. The -th line contains two integers, and : the position and the shape of the -th ball, respectively.

### Output

For each test case, output one line containing `Case #: `

, where is the test case number (starting from 1) and is the *minimum* number of units of power needed to transfer all of the balls to the warehouse, as described above.

### Limits

Time limit: 40 seconds.

Memory limit: 1 GB.

.

, for all .

, for all .

.

, for all .

All are distinct.

#### Test Set 1 (Visible Verdict)

For at most 15 cases:

.

For the remaining cases:

.

#### Test Set 2 (Hidden Verdict)

For at most 15 cases:

.

For the remaining cases:

.

## No comments:

## Post a Comment