This page is still under construction.

Parts of this page are still being built. What you see may change.

Help-or-else

Time limit1sMemory limit128 MB

Summary
Choose an ordered subset of people to help; the finish time of each helper accumulates, and unhelped people add a penalty, so find the largest feasible subset under budget K.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Sorting, Array
Solved
No attempts yet

Problem

A correctional facility is about to hold its yearly community-service event under some strict rules. Each participant is assigned a set PP of NN people whose finances they may help with, together with a time budget of KK minutes.

For the jj-th person (1≤j≤N1 \le j \le N) two integers are known: a penalty eje_j that is charged if the participant chooses not to advise that person, and a duration djd_j (in minutes) required to advise that person.

The participant starts at time T=0T = 0. If they begin working with the jj-th person at time TT, they must finish no later than T+djT + d_j; a value Cj=T+djC_j = T + d_j is charged, and they may not start working with anyone else before time T+djT + d_j (people are helped one at a time, back to back).

Let SS be the set of people who are actually helped. The total number of minutes used is

∑x∈SCx+∑x∈P∖Sex.\sum_{x \in S} C_x + \sum_{x \in P \setminus S} e_x.

Write a program that computes the maximum number of people a participant can help without the total used minutes exceeding the limit KK.

Input

The input contains the data for several participants. Each participant's description begins with a line holding two integers NN and KK, separated by a single space: the number of people and the time budget, with 0<N≤2000 < N \le 200 and 0<K≤60000 < K \le 6000. Each of the following NN lines contains two integers separated by a single space — the penalty and the duration of one person to be assisted — with every integer between 00 and 1000010000 inclusive. The input terminates with a line containing two zeros.

Output

For each participant, print a single line in the form i: X, where i is the participant's index counted from 11 in the order the participants appear, and X is the maximum number of people that can be helped without exceeding the KK-minute limit. If it is impossible to keep the total used minutes within KK, print i: Mission Impossible instead.

Examples1

  1. Example 1

    Input
    1 1000
    100 1000
    2 100
    1000 1000
    20 10
    1 1
    0 10000 
    4 293
    61 30
    295 39
    206 27
    94 85
    0 0
    
    Expected output
    1: 1
    2: Mission Impossible
    3: 0
    4: 3