PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000049. Hiệu sách II (Book Shop II)
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 II (Book Shop II)
Book Shop II
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
A bookstore sells different titles. Title costs per copy, each copy has pages, and at most copies are available. Your budget is . You may buy any integer number of copies from to of each title; each purchased copy contributes pages. Find the maximum number of pages obtainable within your budget.
Input
The first line contains . The next three lines contain the prices , the page counts , and the copy limits , respectively.
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
3 10
2 6 3
8 5 4
3 5 2
Output
28
Explanation
Buy three copies of book 1 and one copy of book 3. Cost is and page count is , which is optimal.