# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

A flock of chickens is running east along a straight, narrow road. Each one is running with its own constant speed. Whenever a chick catches up to the one in front of it, it has to slow down and follow at the speed of the other chick. You are in a mobile crane behind the flock, chasing the chicks towards the barn at the end of the road. The arm of the crane allows you to pick up any chick momentarily, let the chick behind it pass underneath and place the picked up chick back down. This operation takes no time and can only be performed on a pair of chicks that are immediately next to each other, even if 3 or more chicks are in a row, one after the other.

Given the initial locations **X _{i}** at time 0 and natural speeds

You may think of the chicks as points moving along a line. Even if **3** or more chicks are at the same location, next to each other, picking up one of them will only let one of the other two passes through. Any swap is instantaneous, which means that you may perform multiple swaps at the same time, but each one will count as a separate swap.

The first line of the input gives the number of test cases, **C**. **C** test cases follow. Each test case starts with **4** integers on a line – **N, K, B** and **T**. The next line contains the **N** different integers **X _{i}**, in increasing order. The line after that contains the

The input variables will maintain the following limits:

All the **X _{i}**’s will be distinct and in increasing order.

1 ≤ B ≤ 1,000,000,000

1 ≤ T ≤ 1,000

0 ≤ Xi < B

1 ≤ Vi ≤ 100

1 ≤ N ≤ 50

0 ≤ K ≤ N

For each test case, output one line containing “**Case #x: S**”, where x is the case number (starting from **1**) and **S** is the smallest number of required swaps, or the word “**IMPOSSIBLE**”.

Input | Output |
---|---|

3 5 3 10 5 0 2 5 6 7 1 1 1 1 4 5 3 10 5 0 2 3 5 7 2 1 1 1 4 5 3 10 5 0 2 3 4 7 2 1 1 1 4 |
Case #1: 0 Case #2: 2 Case #3: IMPOSSIBLE |

100% Solution Ratio

Labib666Earliest,

Labib666Fastest, 97.1s

Labib666Lightest, 131 kB

sahedsohelShortest, 3940B

Login to submit