Button Bashing

Interview

Time limit1sMemory limit256 MB

Summary
Press add and subtract buttons from 0, clamped between 0 and 3600, to reach a target time in the fewest presses or the nearest reachable longer time.
Level

Medium4 of 10

Topics
BFS, Shortest path, Graph
Solved
No attempts yet

Problem

You bought a new microwave, and it has a lot of buttons for entering the cooking time quickly. Some buttons add time and some subtract it. You want to enter the cooking time you have in mind with as few button presses as possible.

The cooking time is at least 0 seconds and at most 1 hour. If a button press would make the cooking time less than 0 seconds, the microwave sets the cooking time to 0 seconds. If a button press would make the cooking time more than 1 hour, the microwave sets the cooking time to 1 hour. The cooking time starts at 0 seconds. At least one button always adds 1 second or more.

Given the buttons of the microwave and a desired cooking time, find the smallest number of button presses that reaches that time. If the desired time cannot be entered exactly, find the shortest reachable cooking time that is not below the target, and the smallest number of button presses that reaches it. The cooking time cannot be changed once the microwave starts cooking.

Input

The first line has the number of test cases, a positive integer of at most 100.

Each test case has two lines.

  • One line with two space-separated integers nn and tt (1≤n≤161 \le n \le 16, 0≤t≤36000 \le t \le 3600): the number of buttons available and the desired cooking time in seconds.
  • One line with nn space-separated integers bib_i (−3600≤bi≤3600-3600 \le b_i \le 3600): the number of seconds added to the cooking time when button ii is pressed.

Output

For each test case, print one line with two space-separated integers: the minimum number of button presses needed, and the minimum number of extra seconds that the microwave must run beyond the target.

Examples3

  1. Example 1

    Input
    2
    3 50
    -10 10 60
    1 50
    20
    
    Expected output
    2 0
    3 10
    
  2. Example 2

    Input
    3
    1 0
    1
    2 0
    -5 3
    1 0
    3600
    
    Expected output
    0 0
    0 0
    0 0
    
  3. Example 3

    Input
    3
    1 3600
    3600
    1 3600
    1
    1 3599
    3600
    
    Expected output
    1 0
    3600 0
    1 1