#P13216. [GCJ 2015 #1A] Haircut

[GCJ 2015 #1A] Haircut

题目描述

You are waiting in a long line to get a haircut at a trendy barber shop. The shop has BB barbers on duty, and they are numbered 11 through BB. It always takes the kkth barber exactly MkM_k minutes to cut a customer's hair, and a barber can only cut one customer's hair at a time. Once a barber finishes cutting hair, he is immediately free to help another customer.

While the shop is open, the customer at the head of the queue always goes to the lowest-numbered barber who is available. When no barber is available, that customer waits until at least one becomes available.

You are the NN-th person in line, and the shop has just opened. Which barber will cut your hair?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow; each consists of two lines. The first contains two space-separated integers BB and NN -- the number of barbers and your place in line. The customer at the head of the line is number 11, the next one is number 22, and so on. The second line contains M1M_1, M2M_2, \dots , MBM_B.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the test case number (starting from 11) and yy is the number of the barber who will cut your hair.

3
2 4
10 5
3 12
7 7 7
3 8
4 2 1
Case #1: 1
Case #2: 3
Case #3: 1

提示

Sample Explanation

In Case #1, you are the fourth person in line, and barbers 11 and 22 take 1010 and 55 minutes, respectively, to cut hair. When the shop opens, the first customer immediately has the choice of barbers 11 and 22, and she will choose the lowest-numbered barber, 11. The second customer will immediately be served by barber 22. The third customer will wait since there are no more free barbers. After 55 minutes, barber 22 will finish cutting the second customer's hair, and will serve the third customer. After 1010 minutes, both barbers 11 and 22 will finish; you are next in line, and you will have the choice of barbers 11 and 22, and will choose 11.

Limits

  • 1T1001 \leq T \leq 100.
  • 1N1091 \leq N \leq 10^9.

Small dataset(11 Pts)

  • Time limit: 240 5 seconds.
  • 1B51 \leq B \leq 5.
  • 1Mk251 \leq M_k \leq 25.

Large dataset

  • Time limit: 480 10 seconds.
  • 1B10001 \leq B \leq 1000.
  • 1Mk1000001 \leq M_k \leq 100000.