ZOJ 3410 Layton's Escape
Professor Layton is a renowned archaeologist from London's Gressenheller University. He and his apprentice Luke has solved various mysteries in different places.
![ZOJ 3410 Layton39;s Escape - qhn999 - 码代码的猿猿 layton.jpg](http://img.bimg.126.net/photo/_-5NZ-LnPX1oM-RQ97OneQ==/4564116747380219141.jpg)
Unfortunately, Layton and Luke are trapped in a pyramid now. To escape from this dangerous place, they need to pass N traps. For each trap, they can use Ti minutes to remove it. If they pass an unremoved trap, they will lose 1 HP. They have K HP at the beginning of the escape and they will die at 0 HP.
Of course, they don't want trigger any traps, but there is a monster chasing them. If they haven't pass the ith trap in Di minutes, the monster will catch and eat them. The time they start to escape is 0, and the time cost on running will be ignored. Please help Layton to escape from the pyramid with the minimal HP cost.
Input
There are multiple test cases (no more than 20).
For each test case, the first line contains two integers N and K (1 <= N <= 25000, 1 <= K <= 5000), then followed by N lines, the ith line contains two integers Ti and Di (0 <= Ti <= 10^9, 0 <= Di <= 10^9).
Output
For each test case, if they can escape from the pyramid, output the minimal HP cost, otherwise output -1.
Sample Input
Sample Output
1-1
Author: JIANG, Kai
Contest: ZOJ Monthly, October 2010
按d排序,如果有陷阱过不去,就去掉用时最长的那个陷阱。。。。。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步