直接上代码
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct NodeType
{
double w,v,p;
/* bool operator<(const NodeType &s) const
{
return p>s.p;
}*/
};
int main()
{
int N,T;
cin>>N>>T;
NodeType A[N];
double V=0,x[N];
//memset(x,0,sizeof(x));
int i=1;
for(i=0;i<N;i++)
{
cin>>A[i].v>>A[i].w;
A[i].p=A[i].v/A[i].w;
}
//sort(A[0],A[N]);
double temp;
for(i=0;i<N;i++)
{
if(A[i].p<A[i+1].p)
{
temp=A[i];
A[i]=A[i+1];
A[i+1]=temp;
}
}
while(A[i].w<T)
{
x[i]=1;
V=V+A[i].v;
T=T-A[i].w;
i++;
}
if(T>0)
{
x[i]=T/A[i].w;
V=V+x[i]*A[i].v;
}