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 ≤ ti ≤ 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.
- 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 ith 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 ith second.
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.
- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 103
- 1 ≤ M ≤ 104
- 1 ≤ X ≤ 50 or X = -1
Input: 2 2 3 2 3 4 2 5 2 -1 4 2 3 Output: 7 0 7 1
In the first example, the first operation arrives at 1st second. Thus it is assigned to lowest id machine i.e. machine 1. This machine will be busy till 3rd second. Similarly machine 2 takes up the second operation and will be busy till 5th second.
Finally 3rd operation will be taken up by machine 1 again and will end at 7th second.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, 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|
Fetching successful submissions
If you are still having problems, see a sample solution here.