CodeForces 138 轮第二题 死亡的祝福

B. Death's Blessing
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

22667733−→6 s→6 s88131333−→−13 s→13 s8833−→8 s→8 s66−→6 s→6 s{}{}
33660055330055335555
The first row represents the health of each monster, the second one — the power of the spells.

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?

Input

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.

Output

For each test case, print one integer — the minimum possible total time to kill all monsters.

输入
4
1
10
0
3
100 1 100
1 100 1
4
2 6 7 3
3 6 0 5
2
1000000000 1000000000
1000000000 1000000000
输出
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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值