PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000042. Đọc sách từ hai chồng (Tsundoku) (Tsundoku)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Đọc sách từ hai chồng (Tsundoku) (Tsundoku)

Tsundoku

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are two stacks of books, AA and BB, with nn and mm books. The ii-th book from the top of AA takes aia_i minutes to read; similarly, the jj-th from the top of BB takes bjb_j minutes. Each move takes and reads the top book from either nonempty stack. The total reading time must not exceed KK. Determine the maximum number of books that can be read.

Input

  • The first line contains n,m,Kn,m,K: the sizes of the two stacks and the time limit.
  • The second line contains nn integers a1,…,ana_1,\ldots,a_n from top to bottom.
  • The third line contains mm integers b1,…,bmb_1,\ldots,b_m from top to bottom.

Output

Print the maximum number of books readable within KK minutes.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤81\le n,m\le8; 1≤K≤1091\le K\le10^9; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for all chỉ số hợp lệ.
  • Subtask 2 (30 points): 1≤n,m≤20001\le n,m\le2000; 1≤K≤1091\le K\le10^9; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for all chỉ số hợp lệ.
  • Subtask 3 (50 points): 1≤n,m≤2000001\le n,m\le200000; 1≤K≤1091\le K\le10^9; 1≤ai,bj≤1091\le a_i,b_j\le10^9 for all chỉ số hợp lệ.

Examples

Input

3 4 240
60 90 120
80 150 80 150

Output

3

Explanation

Read the first two books of stack AA (60+90=15060+90=150 minutes) and the top book of stack BB (8080 minutes), total 230≤240230\le240. Four books cannot be read because every choice of prefixes totaling four books exceeds 240240 minutes.