"Binary heap" K-Way Merger problem (BSOJ1941)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.