You are playing a computer game. To pass the current level, you have to kill a big horde of monsters. In this horde, there are nn monsters standing in the row, numbered from 11 to nn. The ii-th monster has aiai health and a special "Death's Blessing" spell of strength bibi attached to it.
You are going to kill all of them one by one. It takes exactly hh seconds to kill a monster with health hh.
When the ii-th monster dies, it casts its spell that increases the health of its neighbors by bibi (the neighbors of the jj-th monster in the row are the monsters on places j−1j−1 and j+1j+1. The first and the last monsters have only one neighbor each).
After each monster is killed, the row shrinks, so its former neighbors become adjacent to each other (so if one of them dies, the other one is affected by its spell). For example, imagine a situation with 44 monsters with health a=[2,6,7,3]a=[2,6,7,3] and spells b=[3,6,0,5]b=[3,6,0,5]. One of the ways to get rid of the monsters is shown below:
22 | 66 | 77 | 33 | −→6 s→6 s | 88 | 1313 | 33 | −→−13 s→13 s | 88 | 33 | −→8 s→8 s | 66 | −→6 s→6 s | {}{} |
33 | 66 | 00 | 55 | 33 | 00 | 55 | 33 | 55 | 55 |
As a result, we can kill all monsters in 6+13+8+66+13+8+6 == 3333 seconds. Note that it's only an example and may not be the fastest way to get rid of the monsters.
What is the minimum time required to kill all monsters in the row?
The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.
The first line of each test case contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of monsters in the row.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the initial health of corresponding monsters.
The third line contains nn integers b1,b2,…,bnb1,b2,…,bn (0≤bi≤1090≤bi≤109), where bibi is the strength of the spell for the ii-th monster.
It's guaranteed that the sum of nn doesn't exceed 2⋅1052⋅105.
For each test case, print one integer — the minimum possible total time to kill all monsters.
10
203
26
3000000000
这个题只要把所有的怪物的生命值和法术值加起来再减去最高的法术值便能得出闯关时间
#include<stdio.h>
int main() {
int n;
int m;
int e;
int q;
long long sum=0;
int max = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
sum = 0, max = 0;
scanf("%d", &m);
for (int j = 0; j < m; j++) {
scanf("%d", &e);
sum = sum + e;
}
for (int j = 0; j < m; j++) {
scanf("%d", &q);
if (q > max) { max = q; }
sum = sum + q;
}
printf("%lld\n", sum - max);
}
return 0;
}