[PAT-A] 1070 Mooncake(25)
阿新 • • 發佈:2018-12-14
題目描述 |
題目分析 |
程式碼設計 |
//AC程式碼
//zhicheng
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
// zhicheng
// Octobrer,9,2018
typedef struct{double num;double prices;}D;
D d[1005];
bool comp(D a,D b){return (a.prices/a.num)>(b.prices/b.num);}
int main()
{
int n;double k,re=0;scanf("%d %lf",&n,&k);
for(int i=0;i<n;i++) scanf("%lf",&d[i].num);
for(int i=0;i<n;i++) scanf("%lf",&d[i].prices);
sort(d,d+n,comp);
for(int i= 0;k&&i<n;i++)
{
if(k>=d[i].num) {k-=d[i].num;re+=d[i].prices;}
else {re+=(d[i].prices/d[i].num)*k;break;}
}
printf("%.2lf\n",re);
return 0;
}