CF366B.Dima and To-do List
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete k - 1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has n tasks to do, each task has a unique number from 1 to n. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.
你曾帮助迪马度过了一个美好的周末,但现在是时候工作了。自然地,迪马——像所有有女朋友的男人一样——把每件事都做错了。
因娜和迪马此刻在同一个房间里。因娜会在她面前目睹的每一件事后责备迪马。每次因娜因某项任务而责备迪马后,她就会去另一个房间,在那里一边绕圈踱步,一边喃喃抱怨自己心爱的人是多么没用。在此期间,迪马便能平静地完成 k−1 项任务。接着因娜返回,再次就迪马在她面前完成的下一项任务对他进行责备,然后又回到另一个房间。如此循环往复,直至迪马完成全部任务。
总体而言,迪马共有 n 项任务需要完成,每项任务都有一个从 1 到 n 的唯一编号。迪马热爱秩序,因此他会按顺序连续完成任务,但起始任务可以任选。例如,若迪马总共需完成 6 项任务,而他从第 5 项任务开始,则完成顺序为:首先完成第 5 项任务,接着第 6 项,然后第 1 项,再第 2 项,再第 3 项,最后第 4 项。
因娜对迪马的责备(当然始终充满爱意且恰如其分!)既频繁又系统,以至于迪马已非常清楚因娜针对每一项任务所施加的责备“力度”。请帮迪马选择起始任务,使得他所承受的总责备力度最小。
输入格式
The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 103), where a__i is the power Inna tells Dima off with if she is present in the room while he is doing the i-th task.
It is guaranteed that n is divisible by k.
输入的第一行包含两个整数 n 和 k(1 ≤ k ≤ n ≤ 105)。第二行包含 n 个整数 a1, a2, ..., an(1 ≤ ai ≤ 103),其中 ai 表示当 Inna 在房间内时,她对 Dima 做第 i 个任务所施加的“训斥力度”。
保证 n 能被 k 整除。
输出格式
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
在一行中输出迪马应首先完成的任务编号,使得他受到的责备能量最小。如果存在多个解,请输出其中第一个要完成的任务编号最小的解。
输入输出样例
输入#1
6 2 3 2 1 6 5 4
输出#1
1
输入#2
10 5 1 3 5 7 9 9 4 1 8 5
输出#2
3
说明/提示
Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as k = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example k = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.
第一个样例的解释:
如果迪马从第一个任务开始,因娜会以强度 3 对他进行批评;随后迪马可以再完成一个任务(因为 k=2);接着因娜会以强度 1 对第三个任务批评他;再之后,她会以强度 5 对第五个任务批评他。因此,迪马受到的总批评强度为 3+1+5=9。如果迪马改为从第二个任务开始,那么因娜将分别对第 2、第 4 和第 6 个任务批评他,对应强度为 2+6+4=12。
第二个样例的解释:
在第二个样例中,k=5,因此迪马能在两次批评之间完成 4 个任务。于是,若迪马从任务 1 或任务 6 开始,则因娜将对他执行任务 1 和任务 6 进行批评;若从任务 2 或任务 7 开始,则批评任务 2 和任务 7;依此类推。最优方案是选择从任务 3 或任务 8 开始,其中任务 3 编号更小,因此答案为 3。
输入解题思路,AI测评打分。不知道怎么写?