Codeforces Round #252 (Div. 2) 441B. Valera and Fruits

英语不好就是坑啊。这道题把我坑残了啊。5次WA一次被HACK。第二题得分就比第一题高10分啊。

以后一定要加强英语的学习,要不然就跪了。

题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的果实腐烂,必须在两天之内收集起来。给出果园有的树,以及该树上的果实个数,工人每天能够採集的上限,求出这段时间之后,能收集到的最大值。

想法非常easy。优先採集上一天剩下的果实(假设有剩下)。假设还能採集再採集今天成熟的果实。假设採集不玩就把当前天数的果实移动到下一天去优先採集。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
	int n,v;
	int i;
	int ans=0;
	int cnt;
	int c;
	int a[5000],b,d;
	memset(a,0,sizeof(a));
	scanf("%d %d",&n,&v);
	for(i=1;i<=n;i++)
	{
		scanf("%d %d",&b,&d);
		a[b]+=d;
	}
	cnt=0;
	for(i=0;i<=3001;i++)
	{
		c=v;
		if(cnt<=c)
		{
			c-=cnt;
			ans+=cnt;
		}
		else
		{
			ans+=c;
			c=0;
		}
		if(c>=a[i])
		{
			ans+=a[i];
			cnt=0;
		}
		else
		{
			cnt=a[i]-c;
			ans+=c;
		}
	}
	printf("%d
",ans);
	return 0;
}



原文地址:https://www.cnblogs.com/mfrbuaa/p/4020946.html