codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

176A.md (2961B)


      1 Source: https://codeforces.com/problemset/problem/176/A
      2 
      3 A. Trading Business
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 The system has *n* planets in total. On each of them Qwerty can buy or sell items of *m* types (such as food, medicine, weapons, alcohol, and so on). For each planet *i* and each type of items *j* Qwerty knows the following:
     24 
     25 * *a**ij* — the cost of buying an item;
     26 * *b**ij* — the cost of selling an item;
     27 * *c**ij* — the number of remaining items.
     28 
     29 It is not allowed to buy more than *c**ij* items of type *j* on planet *i*, but it is allowed to sell any number of items of any kind.
     30 
     31 Knowing that the hold of Qwerty's ship has room for no more than *k* items, determine the maximum profit which Qwerty can get.
     32 
     33 Input
     34 
     35 The first line contains three space-separated integers *n*, *m* and *k* (2 ≤ *n* ≤ 10, 1 ≤ *m*, *k* ≤ 100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.
     36 
     37 Then follow *n* blocks describing each planet.
     38 
     39 The first line of the *i*-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the *i*-th block follow *m* lines, the *j*-th of them contains three integers *a**ij*, *b**ij* and *c**ij* (1 ≤ *b**ij* < *a**ij* ≤ 1000, 0 ≤ *c**ij* ≤ 100) — the numbers that describe money operations with the *j*-th item on the *i*-th planet. The numbers in the lines are separated by spaces.
     40 
     41 It is guaranteed that the names of all planets are different.
     42 
     43 Output
     44 
     45 Print a single number — the maximum profit Qwerty can get.
     46 
     47 Examples
     48 
     49 Input
     50 
     51 ```
     52 3 3 10  
     53 Venus  
     54 6 5 3  
     55 7 6 5  
     56 8 6 10  
     57 Earth  
     58 10 9 0  
     59 8 6 4  
     60 10 9 3  
     61 Mars  
     62 4 3 0  
     63 8 4 12  
     64 7 2 5
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 16
     71 ```
     72 
     73 Note
     74 
     75 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 (3·6 + 7·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3·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.