Maximize the max

Maximize the max

Time Limit: 3.0 s

Memory Limit: 512.0 MB

Description

Alice has two array of integers \(A\) and \(B\) of length \(N\).

The score of the array A is defined as :
lets say Alice has chosen a sequence of indices \(i_1,i_2,i_3....i_k\) where the condition \(A_{i_1} < A_{i_2} < A_{i_3} < .... A_{i_k}\) follows. Then the score of the array is \(B_{i_1} + B_{i_2} + B_{i_3}...+B_{i_k}\)

Alice wants to acheive as much score as possible from the array. But he also wants the array to be as small as possible. Then he figured out that deleting some elements from the beginning of the array does not effect the score. So Alice wants to figure out whats the minimum size of the final array \(A\) after deleting some elements from the beginning and the score of the array remains maximized.

Input

First line takes an integer \(T\) : number of testcases
First line of each testcase takes an integer \(N\) : size of the arrays
Second line takes \(N\) integers \(A_1,A_2,A_3....A_N\)
Third line takes \(N\) integers \(B_1,B_2,B_3.....B_N\)

\(1 <= T <= 10000\)
\(1 <= N <= 2*10^5\)
\(1 <= A_i,B_i <= N\)
sum of \(N\) over all testcase will not exceed \(2*10^5\)

Output

For each testcase, one integer : the minimum size of the final array having maximum possible score.

Sample

Input Output
2
3
1 2 3
1 3 4
4
1 1 3 3
2 2 3 3
3
3

Information

ID
1224
Difficulty
7
Category
(None)
Tags
(None)
# Submissions
54
Accepted
10
Accepted Ratio
19%
Uploaded By