This page is still under construction.

Parts of this page are still being built. What you see may change.

Burrito King

Time limit1sMemory limit256 MB

Summary
Choose fractional amounts of capped ingredients to maximize joy without exceeding the unhappiness budget, and print every value as a reduced fraction.
Level

Medium5 of 10

Topics
Greedy, Sorting, Math
Solved
No attempts yet

Problem

Albert and Barney went to "Burrito King", a restaurant that opened yesterday. Albert received an opening gift card, so the two friends can get one burrito for free. The amount of each ingredient is capped: the burrito holds at most gig_i grams of ingredient ii.

Every ingredient has two satisfaction values. aia_i is the joy that one gram of ingredient ii gives Albert, and bib_i is the unhappiness that the same gram gives Barney. If the burrito holds sis_i grams of ingredient ii, Albert's total joy is

∑i=1nsiai\sum_{i=1}^{n} s_i a_i

and Barney's total unhappiness is

∑i=1nsibi\sum_{i=1}^{n} s_i b_i

Here sis_i is not necessarily an integer, and 0≤si≤gi0 \le s_i \le g_i.

Albert wants his total joy to be at least AA. Barney is his best friend, so Albert wants Barney's total unhappiness to be at most BB. Among the burritos that meet both conditions, Albert picks one with the largest total joy.

Choose the amounts sis_i that meet both conditions, or find out that no such burrito exists.

Input

The first line contains the number of ingredients nn, the joy Albert asks for at least, AA, and the unhappiness Barney is allowed at most, BB (1≤n≤100 0001 \le n \le 100\,000, 0≤A,B≤1090 \le A, B \le 10^9).

Each of the next nn lines describes one ingredient with the maximal number of grams gig_i, the joy per gram aia_i, and the unhappiness per gram bib_i (0≤gi,ai,bi≤1000 \le g_i, a_i, b_i \le 100).

Output

If no burrito meets both conditions, print -1 -1 on the first line.

Otherwise print two lines. The first line holds the maximal joy and the unhappiness that comes with it. The second line holds the amounts s1,…,sns_1, \dots, s_n of ingredients 1 through nn, separated by single spaces.

Print every number as an exact reduced fraction. Print an integer value as p with no denominator, and any other value as p/q (q≥2q \ge 2, gcd⁡(p,q)=1\gcd(p, q) = 1).

Several burritos can reach the maximal joy, so this rule fixes one answer.

  1. Every ingredient with ai=0a_i = 0 or gi=0g_i = 0 gets si=0s_i = 0.
  2. Every remaining ingredient with bi=0b_i = 0 gets si=gis_i = g_i.
  3. Sort the other ingredients by ai/bia_i / b_i in decreasing order, breaking a tie by the smaller index, and walk that order. If the unused part of the unhappiness budget pays for all gig_i grams, use gig_i grams. Otherwise use only the amount the unused part pays for, and leave every later ingredient at 00 grams.

This rule reaches the maximal joy, and among the burritos that reach it the one with the smallest unhappiness.

Examples2

  1. Example 1

    Input
    2 5 5
    2 2 1
    2 2 4
    
    Expected output
    11/2 5
    2 3/4
    
  2. Example 2

    Input
    2 5 5
    2 2 2
    2 2 4
    
    Expected output
    -1 -1