| Homs Collegiate Programming Contest 2026 |
|---|
| Закончено |
You are given two arrays $$$a$$$ and $$$b$$$ both of length $$$n$$$, the score of a range $$$[l, r]$$$ is defined as follows :
i.e the score of a range is the sum of $$$b_i$$$ over all $$$i$$$ such that $$$a_i$$$ is a prefix minimum or a suffix minimum in the range.
Find the maximum score of a range.
Each test contains multiple test cases. The first line contains the number of test cases $$$t (1 \le t \le 5 \cdot 10 ^ 4)$$$. The description of the test cases follows.
The first line of each test case contains the integer $$$n (1 \le n \le 2 \cdot 10 ^ 6)$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n (1 \le a_i \le 10^9)$$$.
The third line of each test case contains $$$n$$$ integers $$$b_1,b_2,\dots,b_n (1 \le b_i \le 10^9)$$$.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10 ^ 6$$$.
For each test case, output one integer: the maximum score of a range.
231 2 13 5 351 2 3 1 27 8 2 4 9
821
| Название |
|---|


