Haybale Feast
InterviewTime limit2sMemory limit512 MB
Pick a contiguous block whose flavor sums to at least M while minimizing the block's maximum spiciness.
- Level
Medium6 of 10
- Topics
- Two pointers, Sliding window, Binary search, Prefix sum
- Solved
- No attempts yet
Problem
Farmer John is preparing a meal for his cows. His barn holds haybales (). The th haybale has flavor () and spiciness ().
The meal is a single course, which is a contiguous interval of one or more 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, and the spiciness of the meal is the maximum spiciness among the haybales in the interval.
Find the minimum spiciness a single-course meal can have, given that its total flavor must be at least ().
Input
The first line contains the integers and , the number of haybales and the minimum total flavor the meal must have. Each of the next lines describes one haybale with two integers, the flavor and then the spiciness .
Output
Print, on a single line, the minimum spiciness of a single-course meal that meets the minimum flavor requirement. At least one such meal always exists.