Counting Garlic - HomeWork

1 problem statement

School is approaching, everyone is busy packing their bags and preparing to go back to school, but I_Love_C is not worried about it! Because his mind is all on summer homework: so far it has not started.

Summer homework is a lot of test papers. Those of us who have climbed out of the test papers know that the questions on the papers include multiple choice questions, fill-in-the-blank questions, short answer questions, and proof questions. The advantage of doing multiple-choice questions is that the workload is very small, but because the multiple-choice questions are generally very long. if there are  55  exam papers, 44  are multiple choice questions and the last one is fill in the blank, obviously it takes longer to do the last one than the first 44  sheets are much longer. But if you only do multiple-choice questions, although the workload is very small, it seems that you have already done \frac{4}{5}54 's work.

I_Love_C decided to use this method to get away with it. He counted the time it took to complete each test paper and the value it could get after it was done (according to the above principle, the more multiple-choice questions, the higher the value of course. ).

Please help him arrange it now, and use the little time he has left to do the most valuable homework.

input format

The test data includes multiple groups. Each set of test data is represented by two integers  M,N(1\leq M\leq 20, 1\leq N\leq 10000)M , N ( 1 M 2 0 , 1 N 1 0 0 0 0 )  start with the number of test papers and the remaining time of I_Love_C respectively. Mis next  M  lines, each line includes two integers  T,V(1\leq T\leq N,0<V<10000)T , V ( 1 T N , 0 < V < 1 0 0 0 0 ) , respectively represent the time required to complete this test paper and the value that can be obtained after completing the test. Input is  0\:0

00  ends.

output format

The maximum value that can be obtained by outputting I_Love_C corresponding to each set of test data. Keep two decimal places.

sample input

Sample output



2 Reference code (C++)

#include<bits/stdc++.h>
using namespace std;

struct node
{
	double t;
	double v;
	double vt;
}a[10000];

bool cmp(node x,node y)
{
	return x.vt>y.vt;
}

intmain()
{
	int M,N,i;
	double sum,b;
	while(true)
	{
	    cin>>M>>N;
		if(M==0&&N==0) break;
		for(i=0;i<M;i++)
		{
			cin>>a[i].t>>a[i].v;
			a[i].vt=a[i].v/a[i].t;
		}
		sort(a,a+M,cmp);
		sum=0;
		b=(double)N;
		for(i=0;i<M;i++)
		{
			if(a[i].t<=b)
			{
				b=b-a[i].t;
				sum=sum+a[i].v;
			}
			else
			{
				sum=sum+a[i].vt*b;
				break;
			}
		}
		cout<<setiosflags(ios::fixed)<<setprecision(2)<<sum<<endl;
	}
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324778775&siteId=291194637