This page is still under construction.

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

King of penalty

Interview

Time limit1sMemory limit16 MB

Summary
Pick the largest set of jobs that finishes before minute P, then order them longest first with idle waiting so the submission times sum to the maximum.
Level

Medium6 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

Jaeui signed up for a strange contest called King of penalty. It works like ICPC, with these rules.

  • The contest runs for PP minutes. The penalty counter starts at 0 and grows by 1 every minute.
  • When a submitted solution is correct, the penalty of that problem is the value of the counter at the moment of submission. The number of submissions does not matter. A problem that is never solved has penalty 0. The total penalty is the sum of the penalties of all problems.
  • A team that solves more problems ranks higher. Among teams that solved the same number of problems, the team with the larger penalty ranks higher.

The moment the contest starts, Jaeui reads all NN problems and works out how many minutes each one costs him. His code is never wrong, and once he starts writing a solution he finishes it before he starts another one. Submitting takes 0 minutes. He picks when to start each problem and may wait and do nothing. He cannot submit after the contest is over, so a solution he finishes writing at minute PP is never submitted.

Suppose P=30P = 30, N=3N = 3, and the three problems cost 2, 12, and 16 minutes. If he writes them from the start in the order 2, 12, 16, the first problem gets penalty 2 and the second gets penalty 14, while the last one is finished at exactly minute 30 and cannot be submitted. He solves two problems for a penalty of 16. That is the largest number of problems, but not the largest penalty. To collect the most penalty he waits until minute 15, then solves the 12 minute problem and the 2 minute problem in that order. The penalty is 27 plus 29, which is 56, and no schedule does better.

Find the largest number of problems Jaeui can solve, and the largest penalty he can collect while solving that many.

Input

The first line contains the contest length PP (1≤P≤1091 \le P \le 10^9) and the number of problems NN (1≤N≤1000001 \le N \le 100000), separated by a space.

The second line contains NN integers separated by spaces. The ii-th integer is the number of minutes Jaeui spends writing problem ii, and it is at least 00 and less than PP.

Output

Print the largest number of problems Jaeui can solve within the contest, and the largest penalty he can collect while solving that many, on one line separated by a space.

Examples2

  1. Example 1

    Input
    30 3
    2 12 16
    
    Expected output
    2 56
    
  2. Example 2

    Input
    11 4
    1 2 3 4
    
    Expected output
    4 30