Week 1 训练赛

这是一篇关于算法训练赛的博客,包含了三个不同题目。第一题是关于消灭怪物的游戏,要求找到消灭所有怪物的最短时间。第二题是一个数字组合问题,要求计算特定条件下所有可能的四位数字密码组合数。第三题涉及单元格染色,判断能否通过印章操作将白色单元格序列染成给定序列。解题关键在于贪心策略和特定情况的处理。
摘要由CSDN通过智能技术生成

T1

CF1749B

题目描述

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 a_iai​ health and a special "Death's Blessing" spell of strength b_ibi​ 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 b_ibi​ (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 \xrightarrow{6\ s}6 s​ 88 1313 33 \xrightarrow{13\ s}13 s​ 88 33 \xrightarrow{8\ s}8 s​ 66 \xrightarrow{6\ s}6 s​ \{\}{} 33 66 00 55 33 00 55 33 55 55 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?

输入格式

The first line contains a single integer tt ( 1 \le t \le 10^41≤t≤104 ) — the number of test cases.

The first line of each test case contains a single integer nn ( 1 \le n \le 2 \cdot 10^51≤n≤2⋅105 ) — the number of monsters in the row.

The second line contains nn integers a_1, a_2, \dots, a_na1​,a2​,…,an​ ( 1 \le a_i \le 10^91≤ai​≤109 ) — the initial health of corresponding monsters.

The third line contains nn integers b

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值