售价是“n个正数”,我看成n个整数,结果debug半天。
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
struct node{
double store,value,rate;
friend bool operator<(const node&a,const node&b){return a.rate>b.rate;}};
int main()
{
int n,need; cin>>n>>need;
vector<node>st(n);
for(int i=0;i<n;++i)cin>>st[i].store;
for(int i=0;i<n;++i)cin>>st[i].value;
for(int i=0;i<n;++i)st[i].rate=st[i].value/st[i].store;
sort(st.begin(),st.end());
double profit=0,bynow=0;
for(int i=0;i<n;++i){
if(bynow<=need-st[i].store){
profit+=st[i].value;
bynow+=st[i].store;}
else{profit+=st[i].rate*(need-bynow); break;}
}
printf("%.2f",profit);
return 0;}