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 did_i, Farmer John sends a delivery of bib_i haybales (1di1014,1bi109)(1 \le d_i \le 10^{14}, 1 \le b_i \le 10^9).

Compute the total number of haybales Bessie will eat during the first TT days.

输入格式

The first line contains NN and TT (1N105,1T1014)(1 \le N \le 10^5, 1 \le T \le 10^{14}).

The next NN lines each contain did_i and bib_i. It is additionally guaranteed that 1d1<d2<<dNT1 \le d_1<d_2<\cdots <d_N \le T.

输出格式

Output the number of haybales that Bessie will eat during the first TT 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 挨饿,有些天 Farmer John 会在早晨(晚餐之前)送来一些干草。具体地说,在第 did_i 天,Farmer John 送来了 bib_i 捆干草(1di1014,1bi1091 \leq d_i \leq 10^{14}, 1 \leq b_i \leq 10^9)。

请计算 Bessie 在前 TT 天内共吃掉了多少捆干草。

输入格式

第一行包含两个整数 NNTT1N105,1T10141 \leq N \leq 10^5, 1 \leq T \leq 10^{14})。

接下来的 NN 行每行包含两个整数 did_ibib_i。保证 1d1<d2<<dNT1 \leq d_1 < d_2 < \cdots < d_N \leq T

输出格式

输出 Bessie 在前 TT 天内吃掉的干草总数。

注意,本题中涉及的整数可能非常大,可能需要使用 64 位整数类型(例如 C/C++ 中的 "long long")。

样例 1 的解释

11 天早晨到达 22 捆干草。Bessie 在第 11 天晚餐时吃掉 11 捆,在第 22 天晚餐时吃掉 11 捆。在第 353 \cdots 5 天,没有干草供 Bessie 吃。在前 55 天中,Bessie 共吃掉 22 捆干草。

样例 2 的解释

11 天早晨到达 22 捆干草。Bessie 在第 11 天和第 22 天各吃掉 11 捆。在第 33 天和第 44 天,没有干草供 Bessie 吃。第 55 天早晨到达 1010 捆干草。Bessie 在第 55 天晚餐时吃掉 11 捆。在前 55 天中,Bessie 共吃掉 33 捆干草。

样例 3 的解释

11 天早晨到达 1010 捆干草。Bessie 在第 141 \cdots 4 天各吃掉 11 捆。第 55 天早晨又到达 1010 捆干草,此时谷仓中共有 1616 捆干草。Bessie 在第 55 天晚餐时再吃掉 11 捆。在前 55 天中,Bessie 共吃掉 55 捆干草。

评分

  • 输入 474-7T105T \leq 10^5
  • 输入 8138-13:无额外限制。
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 11. Bessie eats one haybale for dinner on day 11 and another haybale on day 22. On days 353 \cdots 5, there are no more haybales for Bessie to eat. In total, Bessie eats 22 haybales during the first 55 days.

Explanation for Sample 2

Two haybales arrive on the morning of day 11. Bessie eats one haybale on days 11 and 22. There are no haybales for Bessie to eat on days 33 and 44. On the morning of day 55, 1010 haybales arrive. Bessie eats one haybale for dinner on day 55. In total, Bessie eats 33 haybales during the first 55 days.

Explanation for Sample 3

10 haybales arrive on the morning of day 11. Bessie eats one haybale on days 141 \cdots 4. On the morning of day 55, another 1010 haybales arrive, meaning there are 1616 haybales in the barn. For dinner on day 55, Bessie eats another haybale. In total, Bessie eats 55 haybales during the first 55 days.

SCORING

  • Inputs 474-7: T105T \le 10^5
  • Inputs 8138-13: No additional constraints.