luogu#P9121. [USACO23FEB] Hungry Cow B
[USACO23FEB] Hungry Cow B
题目描述
Bessie is a hungry cow. Each day, for dinner, if there is a haybale in the barn, she will eat one haybale. Farmer John does not want Bessie to starve, so some days he sends a delivery of haybales, which arrive in the morning (before dinner). In particular, on day , Farmer John sends a delivery of haybales .
Compute the total number of haybales Bessie will eat during the first days.
输入格式
The first line contains and .
The next lines each contain and . It is additionally guaranteed that .
输出格式
Output the number of haybales that Bessie will eat during the first days.
Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
题目大意
Bessie 喜欢吃干草。每一天晚上,如果她所在的谷仓里面还有至少一堆干草,Bessie 都会吃一堆当作晚饭。
一开始谷仓里面并没有任何干草,为了不让 Bessie 饿着,FJ 会时不时地给 Bessie 送干草。具体来说,他会在第 天给 Bessie 送来 堆干草,并总共送 次。$(1 \leq N \leq 10^5,1 \leq d_i \leq 10^{14}, 1 \leq b_i \leq 10^9)$。
Bessie 想要知道在前 天她一共能吃多少堆干草,请你帮助她算出这个数值。
请注意数据范围,可能需要使用 long long
来存储部分数据。
Translation by @南阳刘子骥
1 5
1 2
2
2 5
1 2
5 10
3
2 5
1 10
5 10
5
提示
Explanation for Sample 1
Two haybales arrive on the morning of day . Bessie eats one haybale for dinner on day and another haybale on day . On days , there are no more haybales for Bessie to eat. In total, Bessie eats haybales during the first days.
Explanation for Sample 2
Two haybales arrive on the morning of day . Bessie eats one haybale on days and . There are no haybales for Bessie to eat on days and . On the morning of day , haybales arrive. Bessie eats one haybale for dinner on day . In total, Bessie eats haybales during the first days.
Explanation for Sample 3
10 haybales arrive on the morning of day . Bessie eats one haybale on days . On the morning of day , another haybales arrive, meaning there are haybales in the barn. For dinner on day , Bessie eats another haybale. In total, Bessie eats haybales during the first days.
SCORING
- Inputs :
- Inputs : No additional constraints.