#abc338c. C - Leftover Recipes

C - Leftover Recipes

Score: 300300 points

问题描述

你的冰箱里有 NN 种食材。我们称它们为食材 11, \dots, 食材 NN。你拥有 QiQ_i 克的第 ii 种食材。

你可以制作两种类型的菜肴。制作一份 A 类菜肴,你需要每种食材 ii (1iN)(1 \leq i \leq N)AiA_i 克。制作一份 B 类菜肴,你需要每种食材 iiBiB_i 克。你只能制作整数份的每种类型菜肴。

仅使用冰箱中的食材,你能做出的最大总份数是多少?

约束条件

  • 1N101 \leq N \leq 10
  • 1Qi1061 \leq Q_i \leq 10^6
  • 0Ai1060 \leq A_i \leq 10^6
  • 存在一个 ii 使得 Ai1A_i \geq 1
  • 0Bi1060 \leq B_i \leq 10^6
  • 存在一个 ii 使得 Bi1B_i \geq 1
  • 所有输入值都是整数。

输入

输入格式如下:

NN

Q1Q_1 Q2Q_2 \dots QNQ_N

A1A_1 A2A_2 \dots ANA_N

B1B_1 B2B_2 \dots BNB_N

输出

假设你最多可以制作 SS 份菜肴,请输出整数 SS

示例输入 1

2
800 300
100 100
200 10

示例输出 1

5

这个冰箱有 800800 克成分 11300300 克成分 22

你可以用 100100 克成分 11100100 克成分 22 制作一份 A 菜,以及用 200200 克成分 111010 克成分 22 制作一份 B 菜。

制作两份 A 菜和三份 B 菜,你需要 100×2+200×3=800100 \times 2 + 200 \times 3 = 800 克成分 11,以及 100×2+10×3=230100 \times 2 + 10 \times 3 = 230 克成分 22,这些都没有超过冰箱里的存量。这样,你可以总共制作五份菜肴,但是没有办法制作六份,所以答案是 55

示例输入 2

2
800 300
100 0
0 10

示例输出 2

38

你可以用 800800 克成分 11 制作 88 份 A 菜,以及用 300300 克成分 22 制作 3030 份 B 菜,总共 3838 份。

示例输入 3

2
800 300
801 300
800 301

示例输出 3

0

你不能制作任何菜肴。

示例输入 4

10
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000
0 1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1 0

示例输出 4

222222

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Your refrigerator has NN kinds of ingredients. Let us call them ingredient 11, \dots, ingredient NN. You have QiQ_i grams of ingredient ii.

You can make two types of dishes. To make one serving of dish A, you need AiA_i grams of each ingredient ii (1iN)(1 \leq i \leq N). To make one serving of dish B, you need BiB_i grams of each ingredient ii. You can only make an integer number of servings of each type of dish.

Using only the ingredients in the refrigerator, what is the maximum total number of servings of dishes you can make?

Constraints

  • 1N101 \leq N \leq 10
  • 1Qi1061 \leq Q_i \leq 10^6
  • 0Ai1060 \leq A_i \leq 10^6
  • There is an ii such that Ai1A_i \geq 1.
  • 0Bi1060 \leq B_i \leq 10^6
  • There is an ii such that Bi1B_i \geq 1.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

Q1Q_1 Q2Q_2 \dots QNQ_N

A1A_1 A2A_2 \dots ANA_N

B1B_1 B2B_2 \dots BNB_N

Output

Assuming that you can make a maximum total of SS servings of dishes, print the integer SS.

Sample Input 1


2
800 300
100 100
200 10

Sample Output 1


5

This refrigerator has 800800 grams of ingredient 11 and 300300 grams of ingredient 22.

You can make one serving of dish A with 100100 grams of ingredient 11 and 100100 grams of ingredient 22, and one serving of dish B with 200200 grams of ingredient 11 and 1010 grams of ingredient 22.

To make two servings of dish A and three servings of dish B, you need 100×2+200×3=800100 \times 2 + 200 \times 3 = 800 grams of ingredient 11, and 100×2+10×3=230100 \times 2 + 10 \times 3 = 230 grams of ingredient 22, neither of which exceeds the amount available in the refrigerator. In this way, you can make a total of five servings of dishes, but there is no way to make six, so the answer is 55.

Sample Input 2


2
800 300
100 0
0 10

Sample Output 2


38

You can make 88 servings of dish A with 800800 grams of ingredient 11, and 3030 servings of dish B with 300300 grams of ingredient 22, for a total of 3838 servings.

Sample Input 3


2
800 300
801 300
800 301

Sample Output 3


0

You cannot make any dishes.

Sample Input 4


10
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000
0 1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1 0

Sample Output 4


222222

update @ 2024/3/10 01:29:07