PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000069. Trả tiền vừa đủ hoặc hơn (Exact Change)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Trả tiền vừa đủ hoặc hơn (Exact Change)

Exact Change

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

An item costs PP cents. You own nn individual coins or banknotes; note ii has value aia_i and may be used at most once. The seller cannot give change, so the payment must total at least PP. First minimize the total amount paid; among solutions paying the same amount, minimize the number of notes used. The total value of all available notes is guaranteed to be at least PP.

Input

The first line contains the price PP. The second line contains nn. Each of the next nn lines contains a note value aia_i.

Output

Print two integers: the minimum amount paid and the minimum number of notes needed to pay exactly that amount.

Subtasks

The independent scoring groups have the following complete constraints:

  • Subtask 1 (20%): 0≤P≤1000\le P\le100, 1≤n≤121\le n\le12, 1≤ai≤1001\le a_i\le100, ∑ai≥P\sum a_i\ge P.
  • Subtask 2 (30%): 0≤P≤20000\le P\le2000, 1≤n≤401\le n\le40, 1≤ai≤20001\le a_i\le2000, ∑ai≥P\sum a_i\ge P.
  • Subtask 3 (50%): 0≤P≤100000\le P\le10000, 1≤n≤1001\le n\le100, 1≤ai≤100001\le a_i\le10000, ∑ai≥P\sum a_i\ge P.

Examples

Input

1400
3
500
1000
2000

Output

1500 2

Explanation

Using the 10001000 and 500500 bills pays 15001500 with 22 bills. No subset totals between 14001400 and 14991499, so 15001500 is the minimum payment, achieved with the minimum of 22 bills.