• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #214 Div2 B

B. Dima and To-do List
time limit per test 1 second
memory limit per test 256 megabytes
 

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 test(s)
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
Note

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.

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <set>
 5 #include <cstring>
 6 #include <string>
 7 #include <map>
 8 #include <cmath>
 9 #include <ctime>
10 #include <algorithm>
11 #include <queue>
12 
13 using namespace std;
14 #define INF 0x7fffffff
15 #define mod 1000000007
16 #define maxm 1001
17 #define mp make_pair
18 #define pb push_back
19 #define rep(i,n) for(int i = 0; i < (n); i++)
20 #define re return
21 #define fi first
22 #define se second
23 #define sz(x) ((int) (x).size())
24 #define all(x) (x).begin(), (x).end()
25 #define sqr(x) ((x) * (x))
26 #define sqrt(x) sqrt(abs(x))
27 #define y0 y3487465
28 //#define y1 y8687969
29 #define fill(x,y) memset(x,y,sizeof(x))
30 
31 typedef vector<int> vi;
32 typedef long long ll;
33 typedef long double ld;
34 typedef double D;
35 typedef pair<int, int> ii;
36 typedef vector<ii> vii;
37 typedef vector<string> vs;
38 typedef vector<vi> vvi;
39 
40 template<class T> T abs(T x) { re x > 0 ? x : -x; }
41 
42 const int maxn = 115;
43 int n, m, t, k, ans;
44 int x, y;
45 //string s;
46 int p1[maxn], p2[maxn];
47 int a[maxn];
48 int main(){
49     while (~scanf("%d%d", &n,&k)){
50         for (int i = 0; i < n; i++)
51             scanf("%d", &a[i]);
52         ans = INF;
53         for (int i = 0; i < k; i++){
54             x = 0;
55             for (int j = i; j < i+n; j += k)
56                 x += a[j%n];
57             if (ans>x){ ans = x; m = i + 1; }
58         }
59         printf("%d\n", m);
60     }
61     return 0;
62 }
View Code
posted @ 2013-11-25 11:23  HaibaraAi  阅读(108)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3