#K71612. Maximum Problems Solved by Skipping One Problem

    ID: 33571 Type: Default 1000ms 256MiB

Maximum Problems Solved by Skipping One Problem

Maximum Problems Solved by Skipping One Problem

Alice is participating in a programming contest and is presented with N problems, each taking a certain amount of time to solve. However, she is allowed to skip exactly one problem if it helps her maximize the number of problems she can solve within a given total time limit M seconds.

More formally, you are given an integer N representing the number of problems and an integer M representing the time limit. You are also provided with N integers Ti (for i=1,...,N) which denote the time required to solve each problem.

The strategy is as follows:

  • If skipping the problem that takes the longest time (i.e. if \( \sum_{i=1}^{N} T_i - \max(T_i) \leq M \)) allows Alice to possibly solve the remaining \(N-1\) problems, then the answer is \(N-1\).
  • Otherwise, sort the problem times in increasing order and determine the maximum number of problems she can solve in sequence without exceeding M.

For each test case, output the result in the format Case X: Y, where X is the test case number (starting from 1) and Y is the maximum number of problems solved.

Note: It is possible that there are no problems (i.e. N = 0). In that case, the output should be Case X: 0.

All formulas are rendered in \( \LaTeX \) format.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. An integer T representing the number of test cases.
  2. For each test case:
    1. A line with two space-separated integers: N (the number of problems) and M (the time limit in seconds).
    2. If N > 0, a line with N space-separated integers representing the time required for each problem.

outputFormat

For each test case, output a line in the format:

Case X: Y

where X is the case number (starting from 1) and Y is the maximum number of problems Alice can solve.

The output should be sent to standard output (stdout).

## sample
2
5 10
1 2 3 4 5
4 7
4 2 1 3
Case 1: 4

Case 2: 3

</p>