规划假期AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)Takahashi is trying to decide his schedule for $N$ days. Initially, none of the days are holidays.
高桥正在安排接下来 $N$ 天的日程。起初,这些天都不是假期。AI (CI翻译)
He can repeat either of the following operations any number of times:
他可以任意次重复执行以下操作之一:AI (CI翻译)
- Choose an integer
$i$between$1$and$N$, inclusive, and make day$i$a holiday. This operation costs$A_i$. - 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.
- 选择一个
$1$到$N$之间(含)的整数$i$,将第$i$天设为假期。此操作的花费为$A_i$。 - 选择一个
$2$到$N-1$之间(含)的整数$i$,且第$i-1$天和第$i+1$天都已经是假期,然后将第$i$天设为假期。此操作免费。
Find the minimum total cost required to create a consecutive block of $K$ or more holidays.
求至少连续 $K$ 天为假期所需的最小总花费。AI (CI翻译)
$T$ test cases are given; solve each of them.
给定 $T$ 组测试用例,请分别求解。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \leq T \leq 2 \times 10^5$$1 \leq K \leq N \leq 2 \times 10^5$$1 \leq A_i \leq 10^9$- All input values are integers.
- The sum of
$N$over all test cases is at most$2\times 10^5$.
$1 \leq T \leq 2 \times 10^5$$1 \leq K \leq N \leq 2 \times 10^5$$1 \leq A_i \leq 10^9$- 所有输入值均为整数。
- 所有测试用例中
$N$的总和不超过$2\times 10^5$。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Here, $\mathrm{case}_i$ denotes the input for the $i$-th test case. Each test case is given in the following format:
其中,$\mathrm{case}_i$ 表示第 $i$ 组测试用例的输入。每组测试用例的格式如下:AI (CI翻译)
N K
A_1 A_2 \dots A_N
N K
A_1 A_2 \dots A_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $T$ lines. The $i$-th line should contain the answer for the $i$-th test case.
输出 $T$ 行。第 $i$ 行应包含第 $i$ 组测试用例的答案。AI (CI翻译)
样例
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
2
29
1902064780
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。