There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n.
The i-th child wants to get at least ai candies.

Jzzhu asks children to line up. Initially, the i-th child stands at the i-th
place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:

  1. Give m candies to the first child of the line.
  2. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
  3. Repeat the first two steps while the line is not empty.

Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?

Input

The first line contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100).

Output

Output a single integer, representing the number of the last child.

Sample test(s)
input
5 2
1 3 1 4 2
output
4
input
6 4
1 1 2 2 3 3
output
6
Note

Let's consider the first sample.

Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets
2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.

Child 4 is the last one who goes home.


水题,就不多说了,贴代码吧0.0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[110],num[110];
int n,m;
int main()
{
while(cin>>n>>m)
{
memset(num,0,sizeof(num));
for(int i=1;i<=n;i++)
{
cin>>a[i];
while(a[i]>0)
{
a[i]-=m;
num[i]++;
}
}
int k=1,maxn=0;
for(int i=1;i<=n;i++)
{
if(num[i]>=maxn)//此处注意是>=
{
k=i;
maxn=num[i];
}
}
cout<<k<<endl;
}
return 0;
}

(CF#257)A. Jzzhu and Children的更多相关文章

  1. (CF#257)B. Jzzhu and Sequences

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  2. cf #257(Div.2) A. Jzzhu and Children

    A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

    题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...

  4. Codeforces Round #257 (Div. 2) A. Jzzhu and Children

    A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. 450A - Jzzhu and Children 找规律也能够模拟

    挺水的一道题.规律性非常强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的即可了 #include<iostream ...

  6. [CodeForce 450A] Jzzhu and Children

    题目链接:http://codeforces.com/problemset/problem/450/A /* * 计算一个人要是拿足够离开需要排多少次队,选排的次数多的那个人,如果两个人排的次数相同, ...

  7. CF450A 【Jzzhu and Children】

    普通的模拟题这题用一个队列容器来模拟队列元素是pair类型的,first用来存每个小朋友想要的糖数,second用来存小朋友的序号,然后开始模拟,模拟出口是当队列迟到等于1时就输出当前队列里小朋友的序 ...

  8. Codeforces Round #257 (Div. 2/A)/Codeforces450A_Jzzhu and Children

    解题报告 没什么好说的,大于m的往后面放,,,re了一次,,, #include <iostream> #include <cstdio> #include <cstri ...

  9. Codeforces Round #257 (Div. 2)

    A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...

随机推荐

  1. RadioGroup和RadioButton(单选框)

    1.布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...

  2. 150.Evaluate Reverse Polish Notation---逆波兰式求值

    题目链接 题目大意:计算逆波兰表达式的值. 法一:stack,用stack存数,遇到操作符,则运算.代码如下(耗时12ms): public int evalRPN(String[] tokens) ...

  3. Express定制参数解析错误响应值

    Nodejs的Express框架本身所提供的东西并没有其它框架那么多.其中的一个问题就是对于请求数据的解析. express中的请求对象并没有未经过解析的请求体,几乎所有的请求体都要经过类似于body ...

  4. Delphi 7 在程序中直接执行SQL脚本文件

    Delphi 7 在程序中直接执行SQL脚本文件 在处理MSDE一些操作中.需要执行一些SQL脚本.有的是从SQLServer 2000中生成的SQL为后缀的脚本.在MSDE中没有企业管理器,操作都是 ...

  5. Netty源码学习(三)NioEventLoop

    0. NioEventLoop简介 NioEventLoop如同它的名字,它是一个无限循环(Loop),在循环中不断处理接收到的事件(Event) 在Reactor模型中,NioEventLoop就是 ...

  6. #424 Div2 C

    #424 Div2 C 题意 给出 k 个分数,初始分数未知,按顺序把这 k 个分数加到初始分数上,已知 n 个加入分数后的结果(无序),问初始分数有多少种可能. 分析 也就是说这 n 个结果,它们之 ...

  7. 洛谷——P2656 采蘑菇

    P2656 采蘑菇 题目描述 小胖和ZYR要去ESQMS森林采蘑菇. ESQMS森林间有N个小树丛,M条小径,每条小径都是单向的,连接两个小树丛,上面都有一定数量的蘑菇.小胖和ZYR经过某条小径一次, ...

  8. [BZOJ4398]福慧双修/[BZOJ2407]探险

    题目大意: 给定一个$n(n\leq40000)$个点$m(m\leq100000)$条边的有向图,求从$1$出发回到$1$的不经过重复结点的最短路. 思路: 首先Dijkstra求出从1出发到每个结 ...

  9. 一致性hash-java实现treemap版

    把不同号段的数据储存在不同的机器上,以用来分散压力.假如我们有一百万个QQ号,十台机器,,如何划分呢? 最简单粗暴的方法是用QQ号直接对10求余,结果为0-9 分别对应上面的十台机器.比如QQ号为 2 ...

  10. Tiny4412在Ubuntu下给MiniTools添加快捷方式

    解压MiniTools-Linux-20140317.tgz root@ubuntu:~/tiny4412/MiniTools-# ls -l total -rw-r--r-- root root M ...