简单的结构体和排序应用题
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node
{
double sum,zongjia,danjia;
}yuebing[];
bool cmp(node a,node b)
{
return a.danjia>b.danjia;
};
int main()
{
int n,maxn;
cin>>n>>maxn;
int i;
for(i=;i<n;i++)
{
cin>>yuebing[i].sum;
}
for(i=;i<n;i++)
{
cin>>yuebing[i].zongjia;
}
for(i=;i<n;i++)
{
yuebing[i].danjia=yuebing[i].zongjia/yuebing[i].sum;
}
sort(yuebing,yuebing+n,cmp);
double res=0.0;
for(i=;i<n;i++)
{
if(maxn<=)break;
if(maxn>=yuebing[i].sum)
{
maxn-=yuebing[i].sum;
res+=yuebing[i].zongjia;
}
else if(maxn<yuebing[i].sum)
{
res+=maxn*yuebing[i].danjia;
maxn=;
}
}
printf("%.2lf\n",res);
return ;
}