//#include<iostream>
//#include<stdio.h>
//#include<vector>
//#include<algorithm>
//using namespace std;
//
//int main()
//{
// int n;
// double D;
// cin >> n>>D;
// double tmp;
// int id = 0;
// double sum = 0;
// vector<pair<double, double>>mc(n);
// for (int i = 0; i < n; i++)
// {
// cin >> mc[i].first;
// }
// for (int i = 0; i < n; i++)
// {
// cin >> tmp;
// mc[i].second = tmp / mc[i].first;
// }
// sort(mc.begin(), mc.end(),
// [](const auto& a, const auto& b) {
// return a.second > b.second;
// });
// while (id < n&&mc[id].first < D)
// {
// sum = mc[id].first*mc[id].second;
// D = D - mc[id++].first;
// }
// if (id < n&&D)
// {
// sum = sum + D * mc[id].second;
// }
// printf("%0.2f",sum);
//}
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n;
double D;
cin >> n >> D;
double tmp;
double sum = 0;
int id = 0;
vector<double>cake(n), list;
for (int i = 0; i < n; i++)
{
cin >> cake[i];
}
for (int i = 0; i < n; i++)
{
cin >> tmp;
for (int j = 0; j < cake[i]; j++)
{
list.push_back(tmp/cake[i]);
}
}
/*for (int i = 0; i < n; i++)
{
list.push_back(tmp/cake[i]);
}*/
sort(list.begin(),list.end(), greater<double>());
/*while (id < n&&cake[id] < D)
{
sum = sum + list[id] * cake[id];
D = D - cake[id];
id++;
}
if (id < n&&D)
{
sum = sum + D * list[id];
}*/
for (int i = 0; i < D&&i < list.size(); i++)
{
sum = sum + list[i];
}
printf("%0.2f", sum);
system("pause");
return 0;
}
PAT 乙级 1020 月饼 (25分)
最新推荐文章于 2022-04-19 22:47:54 发布