luogu#P4085. [USACO17DEC] Haybale Feast G

    ID: 8113 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>RMQ前缀和枚举暴力线段树USACO2017

[USACO17DEC] Haybale Feast G

题目描述

Farmer John is preparing a delicious meal for his cows! In his barn, he has NN haybales (1N100,0001 \le N \le 100,000). The iith haybale has a certain flavor FiF_i (1Fi1091 \le F_i \le 10^9) and a certain spiciness SiS_i (1Si1091 \le S_i \le 10^9).

The meal will consist of a single course, being a contiguous interval containing one or more consecutive haybales (Farmer John cannot change the order of the haybales). The total flavor of the meal is the sum of the flavors in the interval. The spiciness of the meal is the maximum spiciness of all haybales in the interval.

Farmer John would like to determine the minimum spiciness his single-course meal could achieve, given that it must have a total flavor of at least MM (1M10181 \le M \le 10^{18}).

输入格式

The first line contains the integers NN and MM, the number of haybales and the minimum total flavor the meal must have, respectively. The next NN lines describe the NN haybales with two integers per line, first the flavor FF and then the spiciness SS.

输出格式

Please output the minimum spiciness in a single course meal that satisfies the minimum flavor requirement. There will always be at least one single-course meal that satisfies the flavor requirement.

题目大意

农夫约翰正在为他的奶牛准备一顿美味的晚餐!在他的谷仓里,他有 NN 个干草捆 (1N105)(1 \le N \le 10^5) 。第 ii 个干草捆有一定的风味 Fi(1Fi109)F_i(1 \le F_i \le 10^9) 和一定的辣度 Si(1Si109)S_i(1 \le S_i \le 10^9)

这顿饭将由一道菜组成,是一个连续的区间,包含一个或多个连续的干草捆(农夫约翰不能改变干草捆的顺序)。这顿饭的总体的风味是这段区间里风味的总和。这顿饭的总体辣度是区间中所有草包的最大辣度。

农夫约翰想确定他的这道菜所能达到的最小辣度,但是这道菜的总风味必须至少为 M(1M1018)M(1 \le M \le 10^{18})

输入格式

第一行包含两个整数 NNMM ,分别是干草包的数量和这顿饭必须有的最小风味之和。

接下来的 NN 行,每行两个整数描述这 NN 个草包,首先是风味 FiF_i,然后是辣度 SiS_i

输出格式

请输出这道菜中在满足最低风味时的最低辣度。保证至少有一顿单道菜的饭能满足风味的要求。

5 10
4 10
6 15
3 5
4 9
3 6
9