eolymp
bolt
Try our new interface for solving problems

Balloons

As you know, balloons are handed out during this contest to teams as they solve problems. However, in the past this has sometimes presented challenging logistical problems. One contest hosting site maintained two rooms, \textbf{A} and \textbf{B}, each containing a supply of balloons. There were \textbf{N} teams attending the contest, each sitting in different locations, some being closer to room \textbf{A}, and others to room \textbf{B}. Given the number of balloons needed by each team and each teams distance from room \textbf{A} and room \textbf{B}, what is the minimum total possible distance that must be traveled by all balloons as they are delivered to their respective teams, assuming they are allocated in an optimal fashion from rooms \textbf{A} and \textbf{B}? For the purposes of this problem, assume that the contest staff were cheap and only bought one color of balloon. \InputFile There will be several test cases in the data file. Each test case will begin with a line with three integers: \textbf{N A B} where \textbf{N} is the number of teams (\textbf{1} ≤ \textbf{N} ≤ \textbf{1000}), and \textbf{A} and \textbf{B} are the number of balloons in rooms \textbf{A} and \textbf{B}, respectively (\textbf{1} ≤ \textbf{A}, \textbf{B} ≤ \textbf{10000}). On each of the next \textbf{N} lines there will be three integers, representing information for each team: \textbf{K D_A D_B} where \textbf{K} is the total number of balloons that this team will need, \textbf{D_A} is the distance of this team from room \textbf{A}, and \textbf{D_B} is this teams distance from room \textbf{B} (\textbf{1} ≤ \textbf{D_A}, \textbf{D_B} ≤ \textbf{1000}). You may assume that there are enough balloons - that is, \textbf{∑_i} \textbf{K_i} ≤ \textbf{A} + \textbf{B}. The data file will end with a line with three \textbf{0}s. \OutputFile For each test case, output a single integer, representing the minimum total distance that must be traveled to deliver all of the balloons. Count only the outbound trip, from \textbf{A} or \textbf{B} to the team. Dont count the distance that a runner must travel to return to room \textbf{A} or room \textbf{B}. Print each integer on its own line with no spaces. Do not print any blank lines between answers.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3 15 35
10 20 10
10 10 30
10 40 10
0 0 0
Çıxış verilənləri #1
300