最后一个测试点WA,求大佬
查看原帖
最后一个测试点WA,求大佬
427110
Logiking楼主2021/4/13 21:35
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n,m;
struct farmer{
	int money;
	int L;
}a[10000];
bool cmp(farmer a,farmer b){
	return a.money < b.money;
}
int main(){
	cin >> n >> m;
	int i,j;
	for(i = 1; i <= m; ++i){
		cin >> a[i].money >> a[i].L;
	}
	sort(a+1,a+m+1,cmp);
	long long sum = 0;
	for(i = 1;; ++i){
		if(n == 0)break;
		if(a[i].L < n){
			sum+=a[i].money*a[i].L;
			n -= a[i].L;
		}
		if(a[i].L >= n){
			sum+=a[i].money*n;
			n = 0;
		}
	}
	cout << sum ;
	return 0;
}
2021/4/13 21:35
加载中...