Picking Up Chicks

Count the fewest adjacent swaps so at least K chicks, slowed by slower chicks ahead, reach the barn by time T.

Medium5GreedyArrayInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

A flock of chicks runs east along a straight, narrow road. Each chick runs at its own constant speed. When a chick catches up to the chick in front of it, it slows down and follows at the speed of that chick.

You drive a mobile crane behind the flock and push the chicks toward the barn at the end of the road. The crane arm can lift one chick for an instant, let the chick right behind it pass underneath, and set the lifted chick back down. The operation takes no time, and you can apply it only to a pair of chicks that stand next to each other in the line, even when three or more chicks are bunched together.

You are given the position XiX_i of every chick at time 0, its natural speed ViV_i, and the position BB of the barn. Find the smallest number of lifts you need so that at least KK of the NN chicks reach the barn no later than time TT.

Treat the chicks as points on a line. Even when three or more chicks stand at the same position in a row, lifting one of them lets only one of the other two pass. Every lift is instantaneous, so several lifts may happen at the same moment, and each one counts separately.

Input

The first line contains the number of test cases CC. Each test case takes three lines. The first line has four integers NN, KK, BB and TT. The second line has the NN distinct integers XiX_i in increasing order. The third line has the NN integers ViV_i. Distances are in meters, speeds in meters per second, and times in seconds.

Limits

  • 1C1001 \le C \le 100
  • 1N501 \le N \le 50
  • 0KN0 \le K \le N
  • 1B1091 \le B \le 10^9
  • 1T10001 \le T \le 1000
  • 0Xi<B0 \le X_i < B
  • 1Vi1001 \le V_i \le 100
  • every XiX_i is distinct and the values are given in increasing order

Output

For each test case, print one line of the form Case #x: S, where x is the test case number starting from 1 and SS is the smallest number of lifts. When fewer than KK chicks can reach the barn by time TT, print the word IMPOSSIBLE in place of SS.