Hide

Problem A
Fair Bandwidth Sharing

Dreaming of revolutionizing the tech industry and making the world a better place, Ging has recently moved to Silicon Valley to found his own startup, Katbook.

Katbook allows users to download cat pictures. Katbook is capable of transferring t bits per second.

There are n species of cats, numbered from 1 to n. There is a demand ratio di for the pictures of the i-th species. This means, if there is no further restrictions, the i-th cat species should have a ‘fair share’ of dij=1ndj fraction of the total bandwidth t.

However, because of infrastructure limitations, the bandwidth for the i-th species must be between ai and bi.

You are newly hired by Ging as a network engineer at Katbook. Your first task is to find the most ‘fair’ bandwidth allocation satisfying the above constraints. More formally, let xi be the bandwidth allocated for downloading pictures of the i-th species. You must find xi such that:

  • aixibi,

  • i=1nxi=t,

  • Let yi=tdij=1ndj (yi is the ‘fair share’ bandwidth, if there was no constraints regarding ai and bi), the value i=1n(xiyi)2yi should be as small as possible.

Input

The first line of input contains 2 integers n and t (1n105,1t106).

In the next n lines, the i-th line contains 3 integers ai, bi and di (0aibi106,0<bi,1di106).

It is guaranteed that there exists at least one valid solution.

It can be shown that under these constraints, the solution is unique.

Output

Output n lines, each line contains the allocation for downloading pictures of the i-th species. The answer will be accepted if and only if its relative or absolute error to the optimal solution is at most 106.

Formally, for each line, let your answer be a, and the jury’s answer be b. Your answer is accepted if and only if |ab|max(1,|b|)106.

Explanation of Sample input

In the first sample, each cat species has its ‘fair share’ of 13 of the whole bandwidth.

In the second sample, note that the cat species 1 has much more demand and could get almost all of the available bandwidth if not for its maximum to be capped at 1. The rest is divided with ratio 2:1, hence the cat species 2 gets 6 bits per second and the cat species 3 gets 3 bits per second.

Sample Input 1 Sample Output 1
3 10
0 10 1
0 10 1
0 10 1
3.33333333
3.33333333
3.33333333
Sample Input 2 Sample Output 2
3 10
0 1 1000
2 8 2
2 8 1
1.00000000
6.00000000
3.00000000
Hide

Please log in to submit a solution to this problem

Log in