Mixing Solutions

시간 제한2초메모리 제한2048 MB

요약
각 용기에서 합이 s가 되도록 용액을 덜어낼 때, YY 양의 최악 오차를 최소로 만드는 값을 구한다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 수학
정답자
아직 제출이 없습니다

문제

Let’s prepare for an experiment with the chemical Yokohama Yellow, or YY in short. You have several containers of aqueous solution of YY. While YY is evenly dissolved in each solution, the concentration may differ among containers. You will take arbitrary amounts of solution from some of the containers and mix them to prepare a new solution with the predetermined total amount.

Ideally, the mixed solution should contain the target amount of YY, but there is a problem. While the exact amount of solution in each container is known, the amount of YY in each solution is guaranteed only to fall within a certain range. Due to this uncertainty, it is difficult to match the amount of YY in the mixed solution exactly to the target amount. Still, you can ensure that the error, the difference from the target amount, will never exceed a certain limit.

To be more precise, let the target and actual amounts of YY in the mixed solution be y_ty\_t mg (milligrams) and y_ay\_a mg, respectively. Given the amounts of solution taken from the containers, y_ay\_a is guaranteed to fall within a certain range. The maximum error is defined as the maximum of ∣y_a−y_t∣|y\_a - y\_t| when y_ay\_a varies within this range.

Find the minimum achievable value of the maximum error, given that you can take any portion of the solution in each container as long as their total is equal to the predetermined amount.

입력

The input consists of a single test case of the following format.

nn ss cc

a_1a\_1 l_1l\_1 r_1r\_1

⋮\vdots

a_na\_n l_nl\_n r_nr\_n

The first line contains three integers, nn, ss, and cc, satisfying 1≤n≤10001 ≤ n ≤ 1000, 1≤s≤1051 ≤ s ≤ 10^5, and 0≤c≤M0 ≤ c ≤ M, where M=104M = 10^4 here and in what follows. Here, nn denotes the number of containers of YY solution. The predetermined total amount of the mixed solution is ss mg, and the target amount of YY is cMs\frac{c}{M}s mg. The ii-th of the following nn lines contains three integers, a_ia\_i, l_il\_i, and r_ir\_i, satisfying 1≤a_i≤1051 ≤ a\_i ≤ 10^5 and 0≤l_i≤r_i≤M0 ≤ l\_i ≤ r\_i ≤ M. These integers indicate that the ii-th container has ai mg of solution and that the amount of YY in it is guaranteed to be between l_iMa_i\frac{l\_i}{M}a\_i mg and r_iMa_i\frac{r\_i}{M} a\_i mg, inclusive. They satisfy ∑n_i=1a_i≥s\sum^{n}\_{i=1} {a\_i} ≥ s.

출력

The minimum achievable value of the maximum error can be proven to be a rational number. Express the value as an irreducible fraction p/qp/q with q>0q > 0, and output pp and qq separated by a space on a single line.

예제4

  1. 예제 1

    입력
    3 10 5000
    10 2000 3000
    10 4000 6000
    10 7000 8000
    
    예상 출력
    1 2
    
  2. 예제 2

    입력
    2 10 5000
    7 4500 5500
    12 3500 6000
    
    예상 출력
    4 5
    
  3. 예제 3

    입력
    3 1 4159
    1 1 1
    1 100 100
    1 10000 10000
    
    예상 출력
    0 1
    
  4. 예제 4

    입력
    6 12345 6789
    2718 2818 2845
    9045 2353 6028
    7471 3526 6249
    7757 2470 9369
    9959 5749 6696
    7627 7240 7663
    
    예상 출력
    23901191037 67820000