100 atcoder#ABC172C. [ABC172C] Tsundoku
[ABC172C] Tsundoku
Score : points
Problem Statement
We have two desks: A and B. Desk A has a vertical stack of books on it, and Desk B similarly has books on it.
It takes us minutes to read the -th book from the top on Desk A , and minutes to read the -th book from the top on Desk B .
Consider the following action:
- Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.
How many books can we read at most by repeating this action so that it takes us at most minutes in total? We ignore the time it takes to do anything other than reading.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print an integer representing the maximum number of books that can be read.
3 4 240
60 90 120
80 150 80 150
3
In this case, it takes us , , minutes to read the -st, -nd, -rd books from the top on Desk A, and , , , minutes to read the -st, -nd, -rd, -th books from the top on Desk B, respectively.
We can read three books in minutes, as shown below, and this is the maximum number of books we can read within minutes.
- Read the topmost book on Desk A in minutes, and remove that book from the desk.
- Read the topmost book on Desk B in minutes, and remove that book from the desk.
- Read the topmost book on Desk A in minutes, and remove that book from the desk.
3 4 730
60 90 120
80 150 80 150
7
5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
0
Watch out for integer overflows.