Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show] Hackable ✓
Statistics

Welcome to Mr. Ant Tenna's TV Time! In this round of game, you're given $n$ buckets, where the $i$-th bucket has a maximum capacity of $v_i$ volumes of water. At the start of the game, all buckets will be fully filled with water, and your mission is to keep it contained as much as you can for the next $t$ seconds. But here's the twist: these buckets are broken! The $i$-th bucket has a leaking speed of $l_i$, meaning that every second after the game starts, the $i$-th bucket dribbles away $l_i$ volumes of water.

Before the game starts, you may merge any number of buckets into one. The resulting bucket has a capacity equal to the maximum capacity among the merged buckets, and a leaking speed equal to the minimum leaking speed among the merged buckets. You can do the merging an arbitrary number of times, but they must be performed before filling any water.

Tenna poses $q$ questions, where the $i$-th question has a time limit $t_i$. For each $1 \le i \le q$, calculate the maximum total retained volume after $t_i$ seconds. Note that each question is independent.

Input

There are multiple test cases. The first line of the input contains an integer $T$ ($1 \le T \le 5 \times 10^4$) indicating the number of test cases. For each test case:

The first line contains an integer $n$ ($1 \le n \le 2 \times 10^5$), indicating the number of buckets.

The second line contains $n$ integers $v_1, v_2, \cdots, v_n$ ($1 \le v_i \le 4 \times 10^{13}$), where $v_i$ is the capacity of the $i$-th bucket.

The third line contains $n$ integers $l_1, l_2, \cdots, l_n$ ($0 \le l_i \le 10^9$), where $l_i$ is the leaking speed of the $i$-th bucket.

The fourth line contains an integer $q$ ($1 \le q \le 2 \times 10^5$), indicating the number of questions.

The fifth line contains $q$ integers $t_1, t_2, \cdots, t_q$ ($0 \le t_i \le 10^9$), where $t_i$ is the time limit for the $i$-th query.

It's guaranteed that neither the sum of $n$ nor the sum of $q$ of all test cases will exceed $2 \times 10^5$.

Output

For each test case, output one line containing $q$ integers separated by a space, where the $i$-th integer is the maximum total retained volume after $t_i$ seconds.

Examples

2
4
5 4 7 6
2 1 3 2
3
3 1 2
4
19 47 21 13
5 14 2 3
5
5 2 6 1 4
4 14 8
43 67 38 77 48

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.