#650
Silver II
Farmer John Actually Farms
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John is growing NN (1N21051 \leq N \leq 2\cdot 10^5) plants of asparagus on his farm! However some of his plants have genetic differences, so some plants will grow faster than others. The initial height of the iith plant is hih_i inches, and after each day, the iith plant grows by aia_i inches.

FJ likes some of his plants more than others, and he wants some specific plants to be taller than others. He gives you an array of distinct values t1,,tNt_1,\dots,t_N containing all integers from 00 to N1N-1 and he wants the iith plant to have exactly tit_i other plants that are taller than it. Find the minimum number of days so that FJ's request is satisfied, or determine that it is impossible.

입력

The first will consist of an integer TT, denoting the number of independent test cases (1T10)(1 \leq T \leq 10).

The first line of each test case consists of an integer NN.

The second line consists of NN integers hih_i (1hi109)(1 \leq h_i \leq 10^9) denoting the initial height of the iith plant in inches.

The third line consists of NN integers aia_i (1ai109)(1 \leq a_i \leq 10^9) denoting the number of inches the iith plant grows each day.

The fourth line consists of NN distinct integers tit_i denoting the array that FJ gives you.

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

출력

Output TT lines, the answer to each test case on a different line. If it is not possible, output 1-1.

예제 입력 1

6
1
10
1
0
2
7 3
8 10
1 0
2
3 6
10 8
0 1
2
7 3
8 9
1 0
2
7 7
8 8
0 1
2
7 3
8 8
1 0

예제 출력 1

0
3
2
5
-1
-1

예제 입력 2

2
5
7 4 1 10 12
3 4 5 2 1
2 1 0 3 4
5
4 10 12 7 1
3 1 1 4 5
2 4 3 1 0

예제 출력 2

4
7

점수

Input 3: N2N \le 2Inputs 4-5: N50N \le 50 and ai,hi103a_i, h_i \le 10^3Inputs 6-8: N103N \le 10^3Inputs 9-13: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver II1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.