AT_abc456_f.Plan Holidays

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Takahashi is trying to decide his schedule for NN days. Initially, none of the days are holidays.

He can repeat either of the following operations any number of times:

  • Choose an integer ii between 11 and NN, inclusive, and make day ii a holiday. This operation costs AiA_i.
  • Choose an integer ii between 22 and N−1N-1, inclusive, such that both day i−1i-1 and day i+1i+1 are already holidays, and make day ii a holiday. This operation is free.

Find the minimum total cost required to create a consecutive block of KK or more holidays.

TT test cases are given; solve each of them.

高桥正在规划 NN 天的日程安排。初始时,没有任何一天是假日。

他可以任意次重复以下两种操作之一:

  • 选择一个整数 ii(1≤i≤N1 \le i \le N),将第 ii 天设为假日。该操作花费 AiA_i。
  • 选择一个整数 ii(2≤i≤N−12 \le i \le N-1),使得第 i−1i-1 天和第 i+1i+1 天均已是假日,并将第 ii 天设为假日。该操作免费。

求构造一段长度至少为 KK 的连续假日区间所需的最小总花费。

共给出 TT 组测试数据,请分别求解。

输入格式

The input is given from Standard Input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Here, casei\mathrm{case}_i denotes the input for the ii-th test case. Each test case is given in the following format:

NN KK
A1A_1 A2A_2 …\dots ANA_N

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

其中,casei\mathrm{case}_i 表示第 ii 个测试用例的输入。每个测试用例按以下格式给出:

NN KK
A1A_1 A2A_2 …\dots ANA_N

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。

输入输出样例

  • 输入#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 22 a holiday using the first type of operation. This costs 11.
  • Make day 44 a holiday using the first type of operation. This costs 11.
  • Make day 33 a holiday using the second type of operation. This is free.

The total cost of this sequence of operations is 22. It is impossible to create a consecutive block of two or more holidays with a cost less than 22, so output 22.

Constraints

  • 1≤T≤2×1051 \leq T \leq 2 \times 10^5
  • 1≤K≤N≤2×1051 \leq K \leq N \leq 2 \times 10^5
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • All input values are integers.
  • The sum of NN over all test cases is at most 2×1052\times 10^5.

样例 1 解释:
对于第一个测试用例,可通过如下操作构造一个长度至少为 2 的连续假日区间:

  • 使用第一类操作将第 22 天变为假日,花费为 11。
  • 使用第一类操作将第 44 天变为假日,花费为 11。
  • 使用第二类操作将第 33 天变为假日,该操作免费。

此操作序列的总花费为 22。无法以低于 22 的花费构造出长度不少于 2 的连续假日区间,因此输出 22。

约束条件

  • 1≤T≤2×1051 \leq T \leq 2 \times 10^5
  • 1≤K≤N≤2×1051 \leq K \leq N \leq 2 \times 10^5
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • 所有输入值均为整数。
  • 所有测试用例的 NN 之和不超过 2×1052\times 10^5。

输入解题思路,AI测评打分。不知道怎么写?

首页