Description
There are n functions, F1,f2,..., Fn, respectively. Defines fi (x) =ai*x^2+bi*x+ci (x∈n*). Given these AI, Bi, and CI, request the smallest m of all function values of all functions (if there are duplicates to output multiple).
Input
The first line enters two positive integers n and M. The following n rows are three positive integers per line, where the three digits of line I are AI, bi, and CI respectively. Ai<=10,bi<=100,ci<=10 000.
Output
The output sorts the first m elements of all the function values that can be generated by these n functions. The m number should be output to one line, separated by a space.
Sample Input
3 10
4 5 3
3 4 5
1 7 1
Sample Output
9 12 12 19 25 29 31 44 45 54
Hint
n,m<=10,000
Thinking
First of all, according to the knowledge of the two functions, each function is monotonically increasing in the x>0 range.
This problem can be done according to the idea of the heap. Start by adding the first function value of each function to the small Gan, note that the heap must be recorded as the number of functions. Each time the heap top element is taken to the answer, the function of the top element of the heap is labeled +1, and the newly obtained function value is added to the heap. Repeat the above steps until you remove the M answer.
Time complexity O (MLOGN)
Code
No (Steal a little lazy to write tomorrow)
"Binary heap" K-Way Merger problem (BSOJ1941)