CF2193D.Monster Game

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Monster Game

You have been gifted a new game called "Elatyh". In the game, you are given nn swords, each with its own strength. In particular, the sword numbered ii has a strength of aia_i. The game consists of nn levels, each of which features a monster.

You start at level 11 and progress further. To pass level ii and move on to level i+1i + 1, you need to defeat the monster at level ii. To defeat the monster at level ii, you need to deal it bib_i sword strikes. The swords in the game are very fragile, so they can only deal one strike before breaking. If you complete level nn or run out of swords, you can finish the game and proceed to score calculation.

Before the game, you are allowed to choose the difficulty level. If you choose difficulty xx, swords with a strength less than xx will not affect the monsters. The game score in this case is equal to xx multiplied by the number of levels completed. Your task is to choose the game difficulty in such a way as to maximize the game score.

Input

Each test consists of several test cases. The first line contains a single integer tt (1t1041\le t\le 10^4) — the number of test cases. The following describes the test cases.

The first line of each test case contains a single integer nn (1n21051\le n\le 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai109)(1\le a_i\le 10^9).

The third line of each test case contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n (1bin)(1\le b_i\le n).

It is guaranteed that the sum of the values of nn across all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output a single integer — the maximum game score.

Note

Consider the first test case. Optimal difficulty to choose is 33. If difficulty is 33, you can deal strikes with swords number 22 and 33. With 22 swords you can complete 11 level, so the game score is 31=33\cdot 1 = 3.

Samples

5
3
1 3 4
2 1 1
2
2 3
1 1
4
1 2 3 4
2 2 1 1
6
4 4 1 4 5 4
2 2 4 1 2 2
10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1
3
4
3
8
10000000000

在线编程 IDE

建议全屏模式获得最佳体验