88pts求调
查看原帖
88pts求调
1051379
MYD_DL24楼主2025/8/4 11:21
#include <bits/stdc++.h>
using namespace std;
const int N =2e7;
struct farmer{
	int p,q;
}fm[N];
int n,m,hasmilk = 0,cost = 0;
inline bool cmp(farmer a,farmer b){
	return a.p < b.p;
}
int main(){
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	cin >> n >> m;
	for (int i = 1;i <= m;i++)cin >> fm[i].p >> fm[i].q;
	sort(fm+1,fm+m+1,cmp);
	for (int i = 1;i <= m;i++){
		for (int j = 1;j <= fm[i].q;j++){
			if (hasmilk >= n){
				cout << cost ;
				return 0;
			}
			else hasmilk++;cost += fm[i].p;
		}
	}
	printf("%d",0);
	return 0;
}
2025/8/4 11:21
加载中...