74分求助
查看原帖
74分求助
550979
Kevin_dmld楼主2022/12/17 16:01
#include<bits/stdc++.h>
using namespace std;
struct milkCompany
{
	int production, prize;
}a[1000001];
bool cmp(milkCompany a, milkCompany b)
{
	return a.prize < b.prize;
}
int main(){
	int needMilk, n, needMoney = 0;
	cin>> needMilk >> n;
	for(int i = 1 ; i <= n ; i++) cin>>a[i].prize >> a[i].production;
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1 ; i <= n ; i++)
	{
		if(a[i].production <= needMilk)
		{
			needMoney += a[i].prize * a[i].production;
			needMilk -= a[i].production;
		}
		else
		{
			needMoney += a[i].prize * (a[i].production - needMilk);
			needMilk = 0;
		}
		if(needMilk == 0)
		{
			break;
		}
	}
	cout<<needMoney;
	return 0;
}

2022/12/17 16:01
加载中...