Seongssipdang Meal Kit
Time limit2sMemory limit1024 MB
Given N ingredients with spoilage rates, expiration days, and removable flags, find the latest day x such that after removing at most K non-important ingredients the total bacteria count stays at most G.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Sorting, Implementation
- Solved
- No attempts yet
Problem
Seongssipdang, the bakery that Instagram bread lovers keep coming back to, has used the know-how Suhyeon has built up over the years to branch out into the meal kit business. Now you can enjoy the taste of Seongssipdang at home.
Hanbyeol, a bread lover who would never miss this news, ran straight to Seongssipdang and bought a meal kit. But Hanbyeol was busy solving problems and forgot to eat the meal kit before its expiration date. Holding back tears, Hanbyeol opened the package to throw the meal kit away, and at that moment discovered that each ingredient has a different expiration date. Because a meal kit's expiration date is determined by the earliest expiration date among all its ingredients, some ingredients whose expiration dates had not yet passed were still left.
A meal kit contains ingredients. The -th ingredient has an expiration date of days after the meal kit is purchased and a spoilage rate of . At days after purchase, the number of bacteria in the -th ingredient is
individuals. Here, is an integer.
If the sum of the numbers of bacteria in all ingredients is at most individuals, the meal kit can be eaten without worry. Hanbyeol, who wants very much to try the meal kit, decided to remove up to ingredients that are not important, and if the number of bacteria becomes at most individuals, to just eat it.
How many days after buying the meal kit can Hanbyeol eat it?
Input
The first line gives separated by spaces.
From the second line, among the lines, the -th line gives the information for the -th ingredient: the spoilage rate , the expiration date , and a number indicating whether it is an important ingredient. is or , and means the ingredient is not important and can be removed.
Output
When up to ingredients that are not important are removed, output how many days after purchase the meal kit can be eaten.
Constraints
- The sum of over all ingredients does not exceed . ()
- All numbers given as input are integers.