CF2183H.Minimise Cost
NOI/NOI+/CTSC
通过率:0%
时间限制:6.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For any sequence b of length m, we define its cost function f(b) as: $$ f(b) = m \cdot \sum_{i=1}^m b_i.$$
You are given a sequence a of length n and an integer k.
Your task is to partition the sequence a into exactly k non-empty subsequences∗, denoted as s1,s2,…,sk. Every element of the original sequence a must belong to exactly one of these subsequences.
Find the minimum possible value of the total cost: $$ \sum_{i=1}^k f(s_i).$$
∗A sequence c is a subsequence of a sequence d if c can be obtained from d by the deletion of several (possibly, zero or all) element from arbitrary positions.
对于任意长度为 m 的序列 b,我们定义其代价函数 f(b) 为:
f(b)=m⋅i=1∑mbi.
给定一个长度为 n 的序列 a 和一个整数 k。
你的任务是将序列 a 恰好划分为 k 个非空子序列∗,记作 s1,s2,…,sk。原始序列 a 中的每个元素必须且仅属于这 k 个子序列中的一个。
求总代价的最小可能值:
i=1∑kf(si).
∗ 序列 c 是序列 d 的一个子序列,当且仅当 c 可通过从 d 中删除若干(可能为零个或全部)位于任意位置的元素而得到。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line contains two integers n and k (1≤k≤n≤2⋅105) — the length of the sequence and the number of subsequences required.
The second line contains n integers a1,a2,…,an (−109≤ai≤109) — the elements of the sequence a.
It is guaranteed that the sum of n across all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
第一行包含两个整数 n 和 k(1≤k≤n≤2⋅105)—— 分别表示序列的长度以及所需子序列的个数。
第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109)—— 序列 a 的元素。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output a single integer – the minimum sum of cost over all subsequences.
对于每个测试用例,输出一个整数——所有子序列的最小成本总和。
输入输出样例
输入#1
6 3 2 1 3 -2 3 1 1 3 -2 10 4 -4 -6 -8 6 -3 -7 -3 1 6 -5 10 9 1 -2 6 -2 -6 4 3 3 7 -1 20 5 -5 9 -4 10 -2 4 -1 3 5 6 7 9 8 1 0 -6 4 5 8 9 50 26 7 10 10 2 2 1 7 4 4 8 5 8 -10 6 1 4 7 8 0 0 -8 1 1 5 0 0 6 0 7 4 6 0 7 4 -2 0 0 8 1 4 -7 0 6 -9 4 10 8 2 0 9
输出#1
1 6 -239 5 131 -404
说明/提示
In the first test case, it is optimal to split into [1,−2] and [3]. The total score is 2(1−2)+1(3)=1.
In the second test case, the only possible way to partition is with 1 subsequence [1,3,−2]. The score is 3(1+3−2)=6.
在第一个测试用例中,最优的划分方式是分成 [1,−2] 和 [3]。总得分为 2(1−2)+1(3)=1。
在第二个测试用例中,唯一可能的划分方式是仅含 1 个子序列 [1,3,−2]。得分为 3(1+3−2)=6。
输入解题思路,AI测评打分。不知道怎么写?