atcoder#ABC219D. [ABC219D] Strange Lunchbox
[ABC219D] Strange Lunchbox
Score : points
Problem Statement
A shop sells kinds of lunchboxes, one for each kind. For each , the -th kind of lunchbox contains takoyaki (octopus balls) and taiyaki (fish-shaped cakes).
Takahashi wants to eat or more takoyaki and or more taiyaki. Determine whether it is possible to buy some number of lunchboxes to get at least takoyaki and at least taiyaki. If it is possible, find the minimum number of lunchboxes that Takahashi must buy to get them.
Note that just one lunchbox is in stock for each kind; you cannot buy two or more lunchboxes of the same kind.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If Takahashi cannot get at least takoyaki and at least taiyaki, print ; otherwise, print the minimum number of lunchboxes that he must buy to get them.
3
5 6
2 1
3 4
2 3
2
He wants to eat or more takoyaki and or more taiyaki. Buying the second and third lunchboxes will get him taiyaki and taiyaki.
3
8 8
3 4
2 3
2 1
-1
Even if he is to buy every lunchbox, it is impossible to get at least takoyaki and at least taiyaki. Thus, print .