PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000042. Hiệu sách (Book Shop)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hiệu sách (Book Shop)
Book Shop
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
A bookshop sells distinct books, one copy of each. Book costs and contains pages. You have at most units of money and cannot purchase a book more than once. Determine the maximum total number of pages obtainable within your budget. You may buy no books.
Input
The first line contains and . The second line contains prices . The third line contains page counts .
Output
Print the maximum number of pages.
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , , .
- Subtask 2 (30%): , , .
- Subtask 3 (50%): , , .
Examples
Input
4 10
4 8 5 3
5 12 8 1
Output
13
Explanation
Buy books 1 and 3 at prices and . Their total price is and they contain pages, which is optimal.