Saving HDU
Time Limit: 3000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 5233 accepted submission (s): 2387
Problem description said that the Haidong group is facing internal and diplomatic difficulties, and the company's elders only have the xhd couple. Obviously, as a businessman who has been fighting for many years, xhd won't sit down.
One day, when he was thinking hard about how to solve the problem, he suddenly thought of his own biography. when the company was founded, his father sent a gift as a gift, and Xu told me at the time, don't open it unless you have. "Isn't it the most necessary time ?", While thinking, xhd found this well-managed tip and opened it. There was only one sentence in it: "Hangzhou North Lu qianrendong youbao ".
Let alone, xhd picked up a big pocket and set off. He knew this qiandongdong. When he was a child, his father took him to this hidden intersection and told him that it was a qiandongdong. Now he understands the meaning of his father's sentence.
Although I was a bit impressed, xhd took a lot of energy to find this unusually hidden hole and walked into it. It was almost stunned and really dazzled! However, although there are many types of baby, there are not many types of baby, of course, the price of each type of baby unit volume is also different, in order to save HDU, now, please help us calculate the maximum value that xhd can bring back as soon as possible? (Assuming that the baby can be split, the value after the split is proportional to the corresponding volume)
The input contains multiple test instances. The first line of each instance is two integers V and N (v, n <100), indicating the size of the pocket and the type of the baby, respectively, the next n rows contain two integers PI and MI (0 <Pi, mi <10), indicating the unit price and corresponding volume of a certain baby, respectively, end input when V is 0.
Output for each test instance, please output the maximum value that xhd can retrieve, each instance occupies a line of output.
Sample Input
2 23 12 30
Sample output
5. Will HDU be out of the crisis after a great deal of help? To learn about the future and listen to the next decomposition --
Authorlcy
Sourceacm programming _ final examination (the time has been set !!)
Recommendlcy | we have carefully selected several similar problems for you: 2109 2107 2108 2110
Classic greedy, not explained.
Code: 0 ms
#include <iostream>#include <stdio.h>#include <algorithm>#define M 1005using namespace std;struct node{double h,w;}v[M];bool cmp(node x,node y){ return x.h>y.h;}int main(){ int i,j,k,n; double cur,m; int c; while(scanf("%lf%d",&m,&n)!=EOF && n &&m) { cur=0; for(i=0;i<n;i++) { scanf("%lf%lf",&v[i].h,&v[i].w); } sort(v,v+n,cmp); for(i=0;i<n;i++) { if(m>=v[i].w) {cur+=v[i].h*v[i].w;m-=v[i].w;} else {cur+=m*v[i].h;break;} } printf("%.0lf\n",cur); } return 0;}