Atli has finally gone off the deep end. After being made to
read yet another Icelandic Saga something broke and he’s going
berserk in Hús Íslenskra Fræða. He’s decided to host a book
burning and is trying to burn as many of the manuscripts and
books in the building as possible. He’s started a fire that
will last seconds. To
keep the fire going for longer he’s running around collecting
written works and tossing them into the fire. Being a
programmer himself, he’s already calculated the optimal route
despite having gone raving mad. Your job is to figure out how
long his fire will last so the university knows how long they
have to catch him red-handed.
Input
The input starts with a line with two integers where
is the number of
written works Atli can grab and is the lifetime of the fire in
seconds. Next there are lines, each with two integers
. This denotes one of the written works Atli can
grab. It takes Atli
seconds to fetch it and once it’s tossed on the fire it extends
its lifetime by
seconds. For this to work the fire has to still be going when
Atli returns after
seconds. If the flame dies the exact moment he returns he can
use the hot ashes to keep things going.
Output
Print the number of seconds Atli can keep the fire
going.
Sample Input 1 |
Sample Output 1 |
3 10
10 20
15 5
12 6
|
36
|