CF176A.Trading Business

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible.

The system has nn planets in total. On each of them Qwerty can buy or sell items of mm types (such as food, medicine, weapons, alcohol, and so on). For each planet ii and each type of items jj Qwerty knows the following:

  • aija_{ij} — the cost of buying an item;
  • bijb_{ij} — the cost of selling an item;
  • cijc_{ij} — the number of remaining items.

It is not allowed to buy more than cijc_{ij} items of type jj on planet ii , but it is allowed to sell any number of items of any kind.

Knowing that the hold of Qwerty's ship has room for no more than kk items, determine the maximum profit which Qwerty can get.

输入格式

The first line contains three space-separated integers nn , mm and kk ( 2<=n<=102<=n<=10 , 1<=m,k<=1001<=m,k<=100 ) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.

Then follow nn blocks describing each planet.

The first line of the ii -th block has the planet's name as a string with length from 11 to 1010 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the ii -th block follow mm lines, the jj -th of them contains three integers aija_{ij} , bijb_{ij} and cijc_{ij} ( 1<=bij<aij<=10001<=b_{ij}<a_{ij}<=1000 , 0<=cij<=1000<=c_{ij}<=100 ) — the numbers that describe money operations with the jj -th item on the ii -th planet. The numbers in the lines are separated by spaces.

It is guaranteed that the names of all planets are different.

输出格式

Print a single number — the maximum profit Qwerty can get.

输入输出样例

  • 输入#1

    3 3 10
    Venus
    6 5 3
    7 6 5
    8 6 10
    Earth
    10 9 0
    8 6 4
    10 9 3
    Mars
    4 3 0
    8 4 12
    7 2 5
    

    输出#1

    16

说明/提示

In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type ( 36+78=743·6+7·8=74 ). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 39+79=903·9+7·9=90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.

首页