贪心选择是每次都要收录单位重量价值最大的礼物
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <memory>
#include <math.h>
#include <algorithm>
using namespace std;
int n,w;
struct node
{
int Value,Height;
double dValue;
};
node gift[105];
bool cmp(const node &a,const node &b)
{
return a.dValue>b.dValue;
}
int main()
{
cin >> n >> w;
double SValue=0.0;
for(int i=0; i<n; i++)
{
cin >> gift[i].Value >> gift[i].Height;
gift[i].dValue = (1.0*gift[i].Value) / (1.0*gift[i].Height);
}
sort(gift,gift+n,cmp);
for(int i=0; i<n; i++)
{
int now = min(gift[i].Height,w);
w-=now;
SValue += now*gift[i].dValue;
if(w==0)
break;
}
printf("%.1f\n",SValue);
return 0;
}