#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct Cake {
double ton;
double price;
double up;
} Cake;
bool cmp(Cake a, Cake b) {
return a.up > b.up;
}
int main(int argc, char *argv[]) {
int n;
double t;
scanf("%d %lf", &n, &t);
Cake *c = new Cake[n];
for (int i = 0; i < n; i++) {
scanf("%lf", &c[i].ton);
}
for (int i = 0; i < n; i++) {
scanf("%lf", &c[i].price);
c[i].up = c[i].price / c[i].ton;
}
sort(c, c + n, cmp);
int i = 0;
double p = 0.0;
while (t > 0 && i < n) {
if (c[i].ton > t) {
p += t * c[i].up;
break;
} else {
p += c[i].price;
t -= c[i].ton;
i++;
}
}
printf("%.2lf\n", p);
return 0;
}
【PAT甲级】1070. Mooncake (25)
最新推荐文章于 2022-06-24 15:04:03 发布