70分,求助
查看原帖
70分,求助
1005749
xzz_0611楼主2023/12/19 20:31

#1 #2 #6有问题

#include<bits/stdc++.h>
using namespace std;
struct str
{
	int u,p;
};
bool cmp(str a,str b)
{
	if(a.p!=b.p) return a.p>b.p;
	else return a.u>b.u;
}
int main()
{
	int n,m,money=0,ans=0;
	str arr[100];
	cin>>n>>m;
	for(int i=0;i<m;i++) cin>>arr[i].u>>arr[i].p;
	sort(arr,arr+m,cmp);
	for(int i=0;i<m;i++)
		if(n-money>=arr[i].u)
		{
			money+=arr[i].u;
			ans+=arr[i].u*arr[i].p;
		}
	cout<<ans;
    return 0;
}
2023/12/19 20:31
加载中...