璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:usaco23feb_hungry_cow_b
problems
名称Hungry Cow B
题目编号USACO23FEB_B1
题目链接luogu.com.cn/…
来源USACO
算法分类入门_循环
难易程度容易

Hungry Cow B

想法

每次只需要维护,最后吃上草的天即可,由于题目保证$T > b_N$,所以最后答案也就在last与T直接修改即可。

代码实现

#include<cstdio>
 
int main()
{
	int n;
	long long int sum = 0, d, b, t, last = 0;
	scanf("%d %lld", &n, &t);
	for(int i=1; i<=n; i++) {
		scanf("%lld %lld", &d, &b);
		if(d >= last)
			last = d + b;
		else
			last += b;
		sum += b;
	}	
	if(t < last)
		sum -= (last - t - 1);
	printf("%lld", sum);
	return 0;
}
/app/www/public/data/pages/icpc/problems/usaco23feb_hungry_cow_b.txt · 最后更改: 2023/05/02 09:27 由 温婕莺