大佬帮忙看看我到底哪里不够贪
#include<bits/stdc++.h>
using namespace std;
struct cost{
double weight,value;
double average;
};
struct pack{
double weight=0,value=0;
};
int main(){
double n,bag;cost a[110];
cin>>n>>bag;
for(int i=1;i<=n;i++){
cin>>a[i].weight>>a[i].value;
a[i].average=a[i].value/a[i].weight;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n-i;j++){
if(a[i].average>a[j].average){
cost p=a[i];a[i]=a[j];
a[j]=p;
}
}
}
pack temp;int cnt=n;
while(temp.weight<bag){
if(temp.weight+a[cnt].weight<bag){
temp.weight+=a[cnt].weight;
temp.value+=a[cnt].value;
}else{
double poor=bag-temp.weight;
temp.weight+=poor;
temp.value+=poor*a[cnt].average;
}
cnt--;
}
printf("%.2f",temp.value);
return 0;
}