P9121 [USACO23FEB] Hungry Cow B
题目描述
Bessie 是一头饥饿的奶牛。每天晚餐时,如果谷仓中有干草,她会吃掉一捆干草。为了防止 Bessie 挨饿,有些天 Farmer John 会在早晨(晚餐之前)送来一些干草。具体地说,在第 $d_i$ 天,Farmer John 送来了 $b_i$ 捆干草($1 \leq d_i \leq 10^{14}, 1 \leq b_i \leq 10^9$)。
请计算 Bessie 在前 $T$ 天内共吃掉了多少捆干草。
输入格式
第一行包含两个整数 $N$ 和 $T$($1 \leq N \leq 10^5, 1 \leq T \leq 10^{14}$)。
接下来的 $N$ 行每行包含两个整数 $d_i$ 和 $b_i$。保证 $1 \leq d_1 < d_2 < \cdots < d_N \leq T$。
输出格式
输出 Bessie 在前 $T$ 天内吃掉的干草总数。
注意,本题中涉及的整数可能非常大,可能需要使用 64 位整数类型(例如 C/C++ 中的 "long long")。
### 样例 1 的解释
第 $1$ 天早晨到达 $2$ 捆干草。Bessie 在第 $1$ 天晚餐时吃掉 $1$ 捆,在第 $2$ 天晚餐时吃掉 $1$ 捆。在第 $3 \cdots 5$ 天,没有干草供 Bessie 吃。在前 $5$ 天中,Bessie 共吃掉 $2$ 捆干草。
### 样例 2 的解释
第 $1$ 天早晨到达 $2$ 捆干草。Bessie 在第 $1$ 天和第 $2$ 天各吃掉 $1$ 捆。在第 $3$ 天和第 $4$ 天,没有干草供 Bessie 吃。第 $5$ 天早晨到达 $10$ 捆干草。Bessie 在第 $5$ 天晚餐时吃掉 $1$ 捆。在前 $5$ 天中,Bessie 共吃掉 $3$ 捆干草。
### 样例 3 的解释
第 $1$ 天早晨到达 $10$ 捆干草。Bessie 在第 $1 \cdots 4$ 天各吃掉 $1$ 捆。第 $5$ 天早晨又到达 $10$ 捆干草,此时谷仓中共有 $16$ 捆干草。Bessie 在第 $5$ 天晚餐时再吃掉 $1$ 捆。在前 $5$ 天中,Bessie 共吃掉 $5$ 捆干草。
### 评分
- 输入 $4-7$:$T \leq 10^5$
- 输入 $8-13$:无额外限制。
说明/提示
### Explanation for Sample 1
Two haybales arrive on the morning of day $1$. Bessie eats one haybale for dinner on day $1$ and another haybale on day $2$. On days $3 \cdots 5$, there are no more haybales for Bessie to eat. In total, Bessie eats $2$ haybales during the first $5$ days.
### Explanation for Sample 2
Two haybales arrive on the morning of day $1$. Bessie eats one haybale on days $1$ and $2$. There are no haybales for Bessie to eat on days $3$ and $4$. On the morning of day $5$, $10$ haybales arrive. Bessie eats one haybale for dinner on day $5$. In total, Bessie eats $3$ haybales during the first $5$ days.
### Explanation for Sample 3
10 haybales arrive on the morning of day $1$. Bessie eats one haybale on days $1 \cdots 4$. On the morning of day $5$, another $10$ haybales arrive, meaning there are $16$ haybales in the barn. For dinner on day $5$, Bessie eats another haybale. In total, Bessie eats $5$ haybales during the first $5$ days.
### SCORING
- Inputs $4-7$: $T \le 10^5$
- Inputs $8-13$: No additional constraints.