[洛谷 1208] [USACO1.4]混合牛奶 Mixing Milk {模拟}

版权声明:请大家斧正,如喜欢的话,为拙见点一个赞吧。 https://blog.csdn.net/qq_39897867/article/details/86713024

题目

https://www.luogu.org/problemnew/show/P1208


解题思路

这道大水模拟题,而我竟然错了?——纯粹为了完成任务。


代码

#include<cstdio>
#include<algorithm>
using namespace std;
struct node{int x,y;}a[5001]; 
int n,k,ans;
bool cmp(node x,node y){return x.x==y.x?x.y>y.y:x.x<y.x;}
int main(){
	scanf("%d%d",&k,&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y); 
	sort(a+1,a+n+1,cmp); 
	int q=1; 
	while (k) if (a[q].y) a[q].y--,ans+=a[q].x,k--; else q++; 
	printf("%d",ans); 
}

猜你喜欢

转载自blog.csdn.net/qq_39897867/article/details/86713024