L2-003. 月饼
仔细读题!!!!!贪心解决。。。
#include<bits/stdc++.h>
#include<cstdlib>
#define ll long long
using namespace std;
const int maxn = 1e5+7;
typedef struct node{
double w;
double yu;
} ;
node no[maxn];
bool cmp(node a, node b){
return a.yu > b.yu;
}
int main()
{
int n,d;
scanf("%d%d",&n, &d);
for(int i = 0; i < n; i++){
double c;
scanf("%lf", &c);
no[i].w = c;
}
for(int i = 0; i < n; i++){
double c;
scanf("%lf", &c);
no[i].yu = c/no[i].w;
}
sort(no, no+n, cmp);
double sum = 0;
for(int i = 0; i < n; i++) {
if(d > no[i].w) {
d -= no[i].w;
sum += no[i].w*no[i].yu;
} else {
sum += d*no[i].yu;
break;
}
}
printf("%.2lf\n", sum);
return 0;
}