AT_abc456_f.Plan Holidays
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Takahashi is trying to decide his schedule for N days. Initially, none of the days are holidays.
He can repeat either of the following operations any number of times:
- Choose an integer i between 1 and N, inclusive, and make day i a holiday. This operation costs Ai.
- Choose an integer i between 2 and N−1, inclusive, such that both day i−1 and day i+1 are already holidays, and make day i a holiday. This operation is free.
Find the minimum total cost required to create a consecutive block of K or more holidays.
T test cases are given; solve each of them.
高桥正在规划 N 天的日程安排。初始时,没有任何一天是假日。
他可以任意次重复以下两种操作之一:
- 选择一个整数 i(1≤i≤N),将第 i 天设为假日。该操作花费 Ai。
- 选择一个整数 i(2≤i≤N−1),使得第 i−1 天和第 i+1 天均已是假日,并将第 i 天设为假日。该操作免费。
求构造一段长度至少为 K 的连续假日区间所需的最小总花费。
共给出 T 组测试数据,请分别求解。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Here, casei denotes the input for the i-th test case. Each test case is given in the following format:
N K
A1 A2 … AN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
其中,casei 表示第 i 个测试用例的输入。每个测试用例按以下格式给出:
N K
A1 A2 … AN
输出格式
Output T lines. The i-th line should contain the answer for the i-th test case.
输出 T 行。第 i 行应包含第 i 个测试用例的答案。
输入输出样例
输入#1
3 5 2 3 1 4 1 5 6 4 24 3 22 39 4 29 15 7 220651272 302798780 874479994 657822311 613294668 479624013 241168404 610547619 762548286 256160531 823041612 951553052 226556081 649525901 153805947
输出#1
2 29 1902064780
说明/提示
Sample 1 Explanation:
For the first test case, a consecutive block of at least two holidays can be created by performing operations as follows:
- Make day 2 a holiday using the first type of operation. This costs 1.
- Make day 4 a holiday using the first type of operation. This costs 1.
- Make day 3 a holiday using the second type of operation. This is free.
The total cost of this sequence of operations is 2. It is impossible to create a consecutive block of two or more holidays with a cost less than 2, so output 2.
Constraints
- 1≤T≤2×105
- 1≤K≤N≤2×105
- 1≤Ai≤109
- All input values are integers.
- The sum of N over all test cases is at most 2×105.
样例 1 解释:
对于第一个测试用例,可通过如下操作构造一个长度至少为 2 的连续假日区间:
- 使用第一类操作将第 2 天变为假日,花费为 1。
- 使用第一类操作将第 4 天变为假日,花费为 1。
- 使用第二类操作将第 3 天变为假日,该操作免费。
此操作序列的总花费为 2。无法以低于 2 的花费构造出长度不少于 2 的连续假日区间,因此输出 2。
约束条件
- 1≤T≤2×105
- 1≤K≤N≤2×105
- 1≤Ai≤109
- 所有输入值均为整数。
- 所有测试用例的 N 之和不超过 2×105。
输入解题思路,AI测评打分。不知道怎么写?