救民于水火

caochenshuo 2023-11-25 16:11:24 3 返回题目

#include<bits/stdc++.h>
using namespace std;
int n,m,s;
struct b{int all,one;}a[5005];
bool cmp(b x,b y){
	if(x.one!=y.one)return x.one<y.one;
	return x.all>y.all;
}
int main(){
	cin>>m>>n;
	for(int i=1;i<=n;i++)cin>>a[i].one>>a[i].all;
	sort(a+1,a+1+n,cmp);
	int i=1;
	while(m){
 	    if(a[i].all!=0){
    	    a[i].all--;
    	    s+=a[i].one;
    	    m--;
    	}
    	else i++;
	}
	cout<<s;
	return 0;
}
{{ vote && vote.total.up }}