#P9344. 去年天气旧亭台
去年天气旧亭台
Background
It is still the weather of the past, and the misty rain over the terraces of the past. Time quietly flows away; the mountains and rivers remain, but the people are no longer the same as before.
Problem Description
Climbing up to the terrace, the old floor covered with dust comes into view.
There are floorboards in total. The floorboards are of two types: the type of the -th floorboard is denoted by , and its dust level is denoted by . Note that is either or .
Now you need to clean the dust on these floorboards. In each operation, you may:
- Choose two indices satisfying , , and the dust on both the -th and the -th floorboards has not been cleaned yet;
- Spend energy to clean the dust on all floorboards from the -th to the -th.
Find the minimum energy required to clean all floorboards.
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
For each test case:
- The first line contains an integer .
- The second line contains integers .
- The third line contains integers .
Output Format
For each test case, output one integer per line, the minimum energy.
2
6
1 1 4 5 1 4
1 0 0 1 0 1
8
3 1 4 1 5 9 2 6
1 0 1 0 1 0 1 0
5
13
Hint
[Sample 1 Explanation]
- For the first test case, directly spend energy to clean all the dust.
- For the second test case, first spend energy to clean the dust on the first floorboard, then spend energy to clean the remaining dust.
[Constraints]
For of the testdata, it is guaranteed that and .
For of the testdata, it is guaranteed that and .
For another of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that , , , and .
Translated by ChatGPT 5