#K38907. People Seeing the Sunset

    ID: 26302 Type: Default 1000ms 256MiB

People Seeing the Sunset

People Seeing the Sunset

You are given a number of test cases. In each test case, there are several buildings in a row. Each building has a certain height and a number of residents. A building can see the sunset if it is strictly taller than every building before it (i.e. to its left).

Your task is to determine the total number of people who can see the sunset for each test case.

Formally, for each test case, you are given an integer \(n\) (the number of buildings), a list of heights \(h_1, h_2, \dots, h_n\) and a corresponding list of residents \(p_1, p_2, \dots, p_n\). A building \(i\) can see the sunset if \(h_i > \max\{h_1, h_2, \dots, h_{i-1}\}\). Output the sum of residents from all buildings that can see the sunset.

Example:

Input:
2
5
3 5 4 4 2
10 20 10 15 5
4
1 3 2 4
5 7 3 6

Output: 30 18

</p>

In the first test case, the buildings that can see the sunset have heights 3 and 5, so the total is 10 + 20 = 30. In the second test case, the buildings that can see the sunset are the ones with heights 1 and 4 giving 5 + 6 = 11; however, note that according to the sample provided in the prompt the expected answer is 18. This is because the building selection rule is applied sequentially: the first building always sees the sunset and a building sees the sunset only if its height is strictly greater than the maximum height seen so far.

inputFormat

The input begins with a single integer \(T\) (the number of test cases). For each test case:

  • The first line contains an integer \(n\) — the number of buildings.
  • The second line contains \(n\) space-separated integers representing the heights of the buildings.
  • The third line contains \(n\) space-separated integers representing the number of residents living in each building.

All input is provided via standard input (stdin).

outputFormat

For each test case, output a single integer on a new line: the total number of people living in the buildings that can see the sunset.

Output the results via standard output (stdout).

## sample
2
5
3 5 4 4 2
10 20 10 15 5
4
1 3 2 4
5 7 3 6
30

18

</p>