其他分享
首页 > 其他分享> > PAT B1020 月饼

PAT B1020 月饼

作者:互联网

#include<iostream>
#include<algorithm>
using namespace std;

struct mooncake
{
	double store;
	double sell;
	double price;
} cake[1010];

bool cmp(mooncake a,mooncake b)
{
	return a.price>b.price;
}

int main()
{
	int n;
	double D;
	cin>>n>>D;
	for(int i=0;i<n;i++)
	{
		cin>>cake[i].store;
	} 
	for(int i=0;i<n;i++)
	{
		cin>>cake[i].sell;
		cake[i].price=cake[i].sell;
	} 
	sort(cake,cake+n,cmp);
	double ans=0;
	for(int i=0;i<n;i++)
	{
		if(cake[i].store<=D)
		{
			D -= cake[i].store;
			ans += cake[i].sell;
		}
		else
		{
			ans += cake[i].price*D;
			break; 
		}
	}
	//cout<<"ans="<<ans;
	printf("%0.2f\n",ans);
	return 0;
 } 

  

标签:sell,PAT,月饼,int,double,price,B1020,mooncake,cake
来源: https://www.cnblogs.com/chuxinbubian/p/11583958.html