Make them work

All submissions for this problem are available.
Its time to put machines into work. There are N machines with 1 ≤ id ≤ N which are initially idle. Certain operations come over a time interval of 1 ≤ t_{i} ≤ M. Remember that operations arrive only at integral times. Each operation requires certain amount of time to be completed. Your task is to assign each operation to a machine if possible. If multiple machines are capable to doing a work , assign it to the machine which has been most idle recently. In case of further ties, choose the machine with the lower id.
Machines can take up a new operation, the exact instant they have completed their previous operation.
Input
 The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
 The first line of each test case contains two space separated integers N and M denoting the number of Machines and maximum time uptill which operations might turn up.
 The i^{th} line of next M lines contain an integer X having two possible types. if X = 1, it represents that no operation has arrived at that particular time. On the other hand X >= 1 represents the time required to complete the operation arriving at i^{th} second.
Output
For each test case, output a single line, two space separated integers A and B. Here, A represents the time at which, after processing all the operations, all the machines will stop and become idle again.
B represents the number of operations that were thrown away and thus couldnt be processed.
Constraints
 1 ≤ T ≤ 20
 1 ≤ N ≤ 10^{3}
 1 ≤ M ≤ 10^{4}
 1 ≤ X ≤ 50 or X = 1
Example
Input: 2 2 3 2 3 4 2 5 2 1 4 2 3 Output: 7 0 7 1
Explanation
In the first example, the first operation arrives at 1^{st} second. Thus it is assigned to lowest id machine i.e. machine 1. This machine will be busy till 3^{rd} second. Similarly machine 2 takes up the second operation and will be busy till 5^{th} second.
Finally 3rd operation will be taken up by machine 1 again and will end at 7^{th} second.
Author:  devamanyu 
Tags  devamanyu 
Date Added:  26102015 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 