[USACO23FEB] Hungry Cow B
题面翻译
Bessie 喜欢吃干草。每一天晚上,如果她所在的谷仓里面还有至少一堆干草,Bessie 都会吃一堆当作晚饭。
一开始谷仓里面并没有任何干草,为了不让 Bessie 饿着,FJ 会时不时地给 Bessie 送干草。具体来说,他会在第 d i d_i di 天给 Bessie 送来 b i b_i bi 堆干草,并总共送 N N N 次。 ( 1 ≤ N ≤ 1 0 5 , 1 ≤ d i ≤ 1 0 14 , 1 ≤ b i ≤ 1 0 9 ) (1 \leq N \leq 10^5,1 \leq d_i \leq 10^{14}, 1 \leq b_i \leq 10^9) (1≤N≤105,1≤di≤1014,1≤bi≤109)。
Bessie 想要知道在前 T T T 天她一共能吃多少堆干草,请你帮助她算出这个数值。 ( 1 ≤ T ≤ 1 0 14 ) (1 \leq T \leq 10^{14}) (1≤T≤1014)
请注意数据范围,可能需要使用 long long
来存储部分数据。
Translation by @南阳刘子骥
题目描述
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 d i d_i di, Farmer John sends a delivery of b i b_i bi haybales ( 1 ≤ d i ≤ 1 0 14 , 1 ≤ b i ≤ 1 0 9 ) (1 \le d_i \le 10^{14}, 1 \le b_i \le 10^9) (1≤di≤1014,1≤bi≤109).
Compute the total number of haybales Bessie will eat during the first T T T days.
输入格式
The first line contains N N N and T T T ( 1 ≤ N ≤ 1 0 5 , 1 ≤ T ≤ 1 0 14 ) (1 \le N \le 10^5, 1 \le T \le 10^{14}) (1≤N≤105,1≤T≤1014).
The next N N N lines each contain d i d_i di and b i b_i bi. It is additionally guaranteed that 1 ≤ d 1 < d 2 < ⋯ < d N ≤ T 1 \le d_1<d_2<\cdots <d_N \le T 1≤d1<d2<⋯<dN≤T.
输出格式
Output the number of haybales that Bessie will eat during the first T T T 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++).
样例 #1
样例输入 #1
1 5
1 2
样例输出 #1
2
样例 #2
样例输入 #2
2 5
1 2
5 10
样例输出 #2
3
样例 #3
样例输入 #3
2 5
1 10
5 10
样例输出 #3
5
提示
Explanation for Sample 1
Two haybales arrive on the morning of day 1 1 1. Bessie eats one haybale for dinner on day 1 1 1 and another haybale on day 2 2 2. On days 3 ⋯ 5 3 \cdots 5 3⋯5, there are no more haybales for Bessie to eat. In total, Bessie eats 2 2 2 haybales during the first 5 5 5 days.
Explanation for Sample 2
Two haybales arrive on the morning of day 1 1 1. Bessie eats one haybale on days 1 1 1 and 2 2 2. There are no haybales for Bessie to eat on days 3 3 3 and 4 4 4. On the morning of day 5 5 5, 10 10 10 haybales arrive. Bessie eats one haybale for dinner on day 5 5 5. In total, Bessie eats 3 3 3 haybales during the first 5 5 5 days.
Explanation for Sample 3
10 haybales arrive on the morning of day 1 1 1. Bessie eats one haybale on days 1 ⋯ 4 1 \cdots 4 1⋯4. On the morning of day 5 5 5, another 10 10 10 haybales arrive, meaning there are 16 16 16 haybales in the barn. For dinner on day 5 5 5, Bessie eats another haybale. In total, Bessie eats 5 5 5 haybales during the first 5 5 5 days.
SCORING
- Inputs 4 − 7 4-7 4−7: T ≤ 1 0 5 T \le 10^5 T≤105
- Inputs 8 − 13 8-13 8−13: No additional constraints.
Scratch实现
后续
接下来我会不断用scratch来实现信奥比赛中的算法题、Scratch考级编程题实现、白名单赛事考题实现,感兴趣的请关注,我后续将继续分享相关内容