B - Dima and To-do List

简介: B - Dima and To-do List


 

B - Dima and To-do List

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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.

Input

The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103), where ai 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.

Output

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.

Sample Input

Input

6 2
3 2 1 6 5 4

Output

1

Input

10 5
1 3 5 7 9 9 4 1 8 5

Output

3

Hint

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.

 

 

 

 

题目分析:

读了好久愣是没都明白题目意思是什么,后来看了别人的博客,才搞明白题意。太坑爹了,读完别人的理解立马吐血。

题目意思是:  

10 5
1 3 5 7 9 9 4 1 8 5

 

10 个任务,5意思: 起点必须是1-5之间的位置。

需要完成任务的数量是10/5=2个你读出来了吗?

做任务的规则是任务编号差是5的倍数,且总的精力耗损最小

列如此数据是   需完成任务是 2个,起点可以是1  2  3  4  5

1:  1 6         1+9=10

2:   2 7       3+4= 7

3:   3 8  5 +1=6

4:   4 9 7+8=15

5:没了   其实是1~5-1 之间的位置为起点。

看见了吧   3 8位置的精力耗损最小那此数据的起点应该是3位置吧!

比葫芦画瓢其它数据也这样就行了。是不是看完了还是很迷茫吧!这就对了,我也在迷茫中。

 

 

 

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define maxn 100001
using namespace std;
int a[maxn];
int main()
{
  int n,k;
  while(~scanf("%d%d",&n,&k))
  {
    for(int i=1;i<=n;i++)
      scanf("%d",&a[i]);
    int min=INF;
    int temp=0,sum;
    for(int i=1;i<=k;i++)
    {
      sum=0;
      for(int j=i;j<=n;j+=k)
        sum+=a[j];
      if(sum<min)
      {
        min=sum;
        temp=i;
      }
    }
    printf("%d\n",temp);
  }
  return 0;
}

 

 

 

 

 

 

 

 

目录
相关文章
|
1月前
|
JavaScript 前端开发
构建一个待办事项列表(To-Do List)应用程序
构建一个待办事项列表(To-Do List)应用程序
|
2天前
|
安全 Java
java线程之List集合并发安全问题及解决方案
java线程之List集合并发安全问题及解决方案
8 1
|
2天前
|
存储 消息中间件 算法
Java中的集合框架详解:List、Set、Map的使用场景
Java中的集合框架详解:List、Set、Map的使用场景
|
7天前
|
存储 安全 Java
Java List详解
Java List详解
|
8天前
|
Java API
使用 Java 来实现两个 List 的差集操作
使用 Java 来实现两个 List 的差集操作
14 3
|
10天前
|
安全 Java 索引
Java List:从入门到精通,一篇文章就够了!
【6月更文挑战第17天】Java List是有序元素集合,支持索引访问、添加、删除和修改。从ArrayList、LinkedList到Vector,各种实现满足不同场景需求。使用add()添加元素,get()获取,set()修改,remove()删除。遍历可用for-each或Iterator,subList()创建子集。注意线程安全,可选synchronizedList()、Vector或CopyOnWriteArrayList。理解List的基本操作和特性,能提升编程效率。
|
10天前
|
存储 Java 索引
告别Java集合小白!一文读懂List的精髓
【6月更文挑战第17天】Java中的List接口作为有序集合,允许存储和操作有序元素,支持重复值。ArrayList和LinkedList是常见实现类:ArrayList基于数组,适合快速访问但插入删除慢;LinkedList基于链表,插入删除快但访问慢。了解其核心概念、方法及泛型使用,能提升编程效率和代码质量。示例代码展示了添加和访问元素。通过深入学习,可以更好地掌握List的高级用法。
|
1天前
|
存储 设计模式 并行计算
CopyOnWriteArrayList:深入理解Java中的线程安全List原理和应用
CopyOnWriteArrayList:深入理解Java中的线程安全List原理和应用
7 0