#6 RE
查看原帖
#6 RE
352350
甄黫陻堙楼主2020/10/6 20:01

实在是想不到哪错了,数组大小也改过,求大佬康康

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
long long ans,xx;
struct st{
	long long p,l;//
}a[5005];
bool cmp(st a,st b){
	if(a.p!=b.p)return a.p<b.p;
}
int main(){
	scanf("%d%d",&n,&m);
	if(m==0||n==0){
		printf("0");
		return 0;
	}
	for(long long i=1;i<=m;i++)scanf("%lld%lld",&a[i].p,&a[i].l);
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=m;i++){
		int sum=0;
		while(sum+1<=a[i].l&&xx+1<=n){
			ans+=a[i].p;
			sum++;xx++;
		}
		if(xx==n)break;
	}
	printf("%lld",ans);
	return 0;
}
2020/10/6 20:01
加载中...