{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003eAs you may know, balloons are handed out during ACM contests to teams as they solve problems. However, this sometimes presents logistical challenges. In particular, one contest hosting site maintains two rooms, A and B, each containing a supply of balloons. There are N teams attending the contest at that site, each sitting at a different location. Some are closer to room A, others are closer to room B, and others are equally distant. Given the number of balloons needed by each team and the distance from each team to room A, and to room 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 A and B? For the purposes of this problem, assume that all of the balloons are identical.\u003c/p\u003e\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003eThere will be several test cases in the input. Each test case will begin with a line with three integers: \u003cem\u003eN A B\u003c/em\u003e.\u003c/p\u003e\r\n\u003cp\u003eWhere \u003cem\u003eN\u003c/em\u003e is the number of teams (1 ≤ \u003cem\u003eN\u003c/em\u003e ≤ 1,000), and \u003cem\u003eA\u003c/em\u003e and \u003cem\u003eB\u003c/em\u003e are the number of balloons in rooms \u003cem\u003eA\u003c/em\u003e and \u003cem\u003eB\u003c/em\u003e, respectively (0 ≤ \u003cem\u003eA,B\u003c/em\u003e ≤ 10,000). On each of the next \u003cem\u003eN\u003c/em\u003e lines there will be three integers, representing information for each team: \u003cem\u003eK DA DB\u003c/em\u003e.\u003c/p\u003e\r\n\u003cp\u003eWhere \u003cem\u003eK\u003c/em\u003e is the total number of balloons that this team will need, \u003cem\u003eDA\u003c/em\u003e is the distance of this team from room \u003cem\u003eA\u003c/em\u003e, and \u003cem\u003eDB\u003c/em\u003e is this team’s distance from room \u003cem\u003eB\u003c/em\u003e\u0026nbsp; (0 ≤ \u003cem\u003eDA,DB\u003c/em\u003e ≤ 1,000). You may assume that there are enough balloons – that is\u003cem\u003e, Σ(K’s) ≤ A+B\u003c/em\u003e. The input will end with a line with three 0s.\u003c/p\u003e\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003eFor 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 room \u003cem\u003eA\u003c/em\u003e or room \u003cem\u003eB\u003c/em\u003e to the team. Don’t count the distance that a runner must travel to return to room \u003cem\u003eA\u003c/em\u003e or room \u003cem\u003eB\u003c/em\u003e. Print each integer on its own line with no spaces. Do not print any blank lines between answers.\u003c/p\u003e\r\n\u003ch3\u003eExample\u003c/h3\u003e\r\n\u003cdiv\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3 15 35\r\n10 20 10 \r\n10 10 30\r\n10 40 10 \r\n0 0 0\r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e300\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\r\n\n\u003c/div\u003e"}}]}