Book Stack

0

0 votes
Problem

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us Ai minutes to read the i-th book from the top on Desk A (1≤i≤N) and Bi minutes to read the i-th book from the top on Desk B (1≤i≤M)

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 K minutes in total? 

Constraints

1≤N,M≤200000

1≤K≤109

1≤Ai,Bi≤109

Input

Input is given from Standard Input in the following format:

N M K
A1 A2 … AN
B1 B2 … BM

 

Output

Print an integer representing the maximum number of books that can be read.

 

 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90minutes, and remove that book from the desk.

Editor Image

?