#P9225. 「PEOI Rd1」寻宝(treasure)

「PEOI Rd1」寻宝(treasure)

Problem Description

One day, wrzSama was treasure hunting, and suddenly fell into a magical room. There are nn machines in this room. Machine ii can produce 2i2^i diamonds.

More specifically, wrzSama can spend aia_i time to start machine ii, and it will produce 2i2^i diamonds. These machines have a very special property: every time he uses machine ii, its start-up time aia_i increases by bib_i. This means that when he wants to get these 2i2^i diamonds for the second time, it will take ai+bia_i + b_i time. The time keeps increasing in this way, and the xx-th start will take ai+(x1)bia_i + (x - 1) b_i time.

wrzSama needs to obtain at least 2n2^n diamonds to get the treasure. Please find the minimum total time required.

Input Format

The first line contains a positive integer nn.

The second line contains nn positive integers, representing a1,a2,,ana_1, a_2, \dots, a_n.

The third line contains nn positive integers, representing b1,b2,,bnb_1, b_2, \dots, b_n.

Output Format

Output one positive integer in a single line, which is the answer.

3
1 2 3
3 2 1
3
3
1 2 100
1 2 1
5
4
1 2 100 100
1 2 1 1
15

Hint

Sample Explanation

Sample 1: directly obtain 232^3, costing time 3.

Sample 2: obtain 2 copies of 212^1, costing time 3, then spend time 2 to obtain one 222^2. In this way, wrzSama can get 2×21+22=8=2n2 \times 2^1 + 2^2 = 8 = 2^n.

Sample 3: obtain 2 copies of 212^1 and 3 copies of 222^2.


Constraints

This problem uses bundled tests.

Subtask Score Special Constraints
11 1616 1n101 \leq n \leq 10
22 1n201 \leq n \leq 20
33 2424 1ai3×1031 \leq a_i \leq 3 \times 10^3
44 4444 None

For 100%100\% of the testdata, it is guaranteed that 1n1031 \le n \le 10^3 and 1ai,bi1071 \le a_i, b_i \le 10^7.

Translated by ChatGPT 5