62求调
查看原帖
62求调
1294496
wu_18楼主2024/11/24 18:52
#include<bits/stdc++.h>
using namespace std;
struct node{
	int dj,sl;
}a[2000005];
bool cmp(node a,node b){
	if(a.dj==b.dj) return a.sl>b.sl;
	return a.dj<b.dj;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n,m,s=0,t=0;
	cin>>n>>m;
	
	for(int i=1;i<=m;i++){
		cin>>a[i].dj>>a[i].sl;
	}
	if(n==0&&m==0){
		cout<<0;
		return 0;
	}
	sort(a,a+m+1,cmp);
	for(int i=1;i<=m;i++){
		for(int j=1;j<=a[i].sl;j++){
			s+=a[i].dj;
			t++;
			if(t==n){
				cout<<s;
				return 0;
			}
		}
	}
	return 0;
}


2024/11/24 18:52
加载中...