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
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đọ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, and , with and books. The -th book from the top of takes minutes to read; similarly, the -th from the top of takes minutes. Each move takes and reads the top book from either nonempty stack. The total reading time must not exceed . Determine the maximum number of books that can be read.
Input
- The first line contains : the sizes of the two stacks and the time limit.
- The second line contains integers from top to bottom.
- The third line contains integers from top to bottom.
Output
Print the maximum number of books readable within minutes.
Subtasks
- Subtask 1 (20 points): ; ; for all chỉ số hợp lệ.
- Subtask 2 (30 points): ; ; for all chỉ số hợp lệ.
- Subtask 3 (50 points): ; ; 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 ( minutes) and the top book of stack ( minutes), total . Four books cannot be read because every choice of prefixes totaling four books exceeds minutes.