刚才RE的情况已经解决完了,但是现在WA了。。。
代码:
#include<bits/stdc++.h>
using namespace std;
double n,t,a,b;
struct element
{
double price=-1,weight=-1;
}x[107];
bool cmp(element x,element y)
{
return x.price<y.price;
}
double check(double u,int h,double money)
{
if(x[h].weight==-1.0) return money;
if(u==0) return money;
if(x[h].weight<=u)
{
double now=money+(x[h].price*x[h].weight);
return check(u-x[h].weight,h+1,now);
}
else
{
double now=money+((x[h].weight-u)*x[h].price);
return check(0,h+1,now);
}
}
int main()
{
cin>>n>>t;
for(int i=0;i<n;i++)
{
cin>>a>>b;
x[i].weight=a;
x[i].price=b/a;
}
sort(x,x+int(n),cmp);
cout<<fixed<<setprecision(2)<<check(t,0,0);
return 0;
}