PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000292. Bột phép thuật - 2 (Magic Powder - 2)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bột phép thuật - 2 (Magic Powder - 2)
Magic Powder - 2
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
One cookie requires grams of every ingredient . There are grams of each ingredient and grams of magic powder. One gram of powder can become one gram of any ingredient. Maximize the number of cookies.
Input
First line: . Next two lines: integers and integers , respectively.
Output
Print one integer: the maximum achievable value.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Examples
Input 1
3 1
2 1 4
11 3 16
Output 1
4
Explanation
Four cookies require (8,4,16) grams; only one gram is missing. Five require more powder.
Input 2
1 1000000000
1
1000000000
Output 2
2000000000
Explanation
Convert all powder into the only ingredient.