Escape from Hell
Time limit2sMemory limit512 MB
Choose an order to use N energy drinks so the climber reaches length L on the earliest day without sinners catching up at night.
- Level
Hard8 of 10
- Topics
- Greedy, Sorting, Implementation, Binary search
- Solved
- No attempts yet
Problem
One day, Buddha looked down into hell and noticed an office worker. The man had done evil, such as forcing unreasonable workloads on his subordinates, but he had done exactly one good deed in his life: he refused an unfair demand from a customer in order to protect his subordinates' lives. Buddha decided that this deed earned him a chance to escape, and lowered a single strand of spider silk into hell.
The office worker started to climb the silk, but the way out is meters long, far too long for one day. He has energy drinks and drinks one of them each day. On the day he drinks the -th drink, he climbs meters during the daytime and then slides down meters during the night. If his height reaches meters or more during the daytime, he escapes at once without sliding down. After days the silk is cut.
He then noticed that other sinners climb the silk every night. During the -th night the sinners climb meters, and they never slide down during the day. If the sinners catch up with the office worker, a fight breaks out and the silk is cut. That is, if the sinners' height is greater than or equal to the office worker's height at the end of any night, he can no longer escape. The office worker and the sinners all start at height 0.
Write a program that chooses the best order in which to drink the energy drinks and prints the earliest day on which the office worker can escape. If he cannot escape, print -1.
Input
The input consists of a single test case.
N L
A1 B1
...
AN BN
C1
...
CN
The first line contains two integers () and (), the number of energy drinks and the length of the spider silk. Among the next lines, the -th line contains two integers () and () describing the -th energy drink: on the day he drinks it, the office worker climbs meters in the daytime and slides down meters at night. Among the following lines, the -th line contains an integer (), the distance the other sinners climb during the -th night.
Output
Print the earliest day on which the office worker can escape. If he cannot escape, print -1.