求救求救,87分!!!悬关
查看原帖
求救求救,87分!!!悬关
778382
wch666楼主2023/12/6 20:30

!!!#6WA!!!

#include<bits/stdc++.h>
using namespace std;
long long n,m,summ;
struct cow{
	long long d,s;
}a[5005];
bool cmpp(cow x,cow y)
{
	if(x.d != y.d)
		return x.d<y.d;
	else if(x.s != y.s)
		return x.s>y.s;
	return true;
}
int main()
{
	cin>>n>>m;
	for(int i=0; i<m; i++)
		cin>>a[i].d>>a[i].s;
	sort(a,a+m,cmpp);
    int i=0;
    while(n > 0)
    {
        if(a[i].s > 0)
        {
            a[i].s--;
            summ+=a[i].d;
            n--;
        }
        else
			i++;
    }
    cout<<summ;
	return 0;
}
2023/12/6 20:30
加载中...