CodeForces 176A Trading Business(贪心)

来源:互联网 发布:miss淘宝店铺号是多少 编辑:程序博客网 时间:2024/04/29 06:06

题意:有n个星球,每个星球有m个物品,买需要ai元,卖bi元,只有ci个,你可以在一个星球最多买k个物品,然后在另外一个星球卖出,问最多能卖多少钱

思路:直接暴力枚举在哪个星球买,哪个星球卖,选差价最大的前k个就行了


#include<bits/stdc++.h>using namespace std;int a[20][200];int b[20][200];int c[20][200];int vis[200];int n,m,k;int solve(int x,int y){memset(vis,0,sizeof(vis));int last = k;int ans = 0;while (last){int flag = 0;int Max = 0;int Maxc = 0;for (int i = 1;i<=m;i++){if (vis[i])continue;if (b[y][i]-a[x][i]>Max){Max = b[y][i]-a[x][i];Maxc = i;flag = 1;}}if (!flag)break;int num = min(last,c[x][Maxc]);ans+=num*Max;vis[Maxc]=1;last-=num;}return ans;}int main(){scanf("%d%d%d",&n,&m,&k);for (int i = 1;i<=n;i++){string s;cin >> s;for (int j = 1;j<=m;j++)scanf("%d%d%d",&a[i][j],&b[i][j],&c[i][j]);}int ans = 0;for (int i = 1;i<=n;i++)for (int j = 1;j<=n;j++)ans = max(ans,solve(i,j));printf("%d\n",ans);}

Description

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 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:

  • aij — the cost of buying an item;
  • bij — the cost of selling an item;
  • cij — the number of remaining items.

It is not allowed to buy more than cij items of type j on planet i, 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 k items, determine the maximum profit which Qwerty can get.

Input

The first line contains three space-separated integers nm and k (2 ≤ n ≤ 101 ≤ m, k ≤ 100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.

Then follow n blocks describing each planet.

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 aijbij and cij (1 ≤ bij < aij ≤ 10000 ≤ cij ≤ 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.

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

Output

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

Sample Input

Input
3 3 10Venus6 5 37 6 58 6 10Earth10 9 08 6 410 9 3Mars4 3 08 4 127 2 5
Output
16

Hint

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.



0 0
原创粉丝点击