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. 结构型设计模式之桥接模式(Bridge)

    结构 意图 将抽象部分与它的实现部分分离,使它们都可以独立地变化. 适用性 你不希望在抽象和它的实现部分之间有一个固定的绑定关系.例如这种情况可能是因为,在程序运行时刻实现部分应可以被选择或者切换. ...

  2. Windows注册与删除mysql服务

    1.删除服务: (1)采用windows自带的服务管理工具:参考:http://www.cnblogs.com/qlqwjy/p/8010598.html sc delete MySQL57 (2)m ...

  3. 华为上机测试题(大数相乘-java)

    PS:这个不是自己写的,测试OK,供参考. /** * 大数相乘 */ public class BigData { public static void main(String[] args) { ...

  4. python--jinja2

    from jinja2 import Template # 创建一个Template模板去渲染它 s = "my name is {{mashiro}}" t = Template ...

  5. jquery做一个表单验证

    正则表达式的写法: var re=new RegExp('规则', '可选参数');var re=/规则/参数;(这个最常用) 正则表达式的规则 和其他语言的正则表达式规则一样,可以参考我的另一边博文 ...

  6. Switch能否用string做参数

    在Java5以前,switch(expr)中,exper只能是byte,short,char,int类型(或其包装类)的常量表达式. 从Java5开始,java中引入了枚举类型,即enum类型. 从J ...

  7. JquerySession使用

    添加数据 $.session.set('key', 'value') 删除数据 $.session.remove('key'); 获取数据 $.session.get('key'); 清除数据 $.s ...

  8. Http与RPC通信协议的比较

    OSI网络结构的七层模型 各层的具体描述如下: 第七层:应用层     定义了用于在网络中进行通信和数据传输的接口 - 用户程式:提供标准服务,比如虚拟终端.文件以及任务的传输 和处理:  第六层:表 ...

  9. 牛客练习赛16 B 漂亮的树【哈希hash/思维】

    链接:https://www.nowcoder.com/acm/contest/84/B 来源:牛客网 题目描述 街上有n棵树,标号为1...n,第i棵树的高度为ai. 定义这n棵树是漂亮的,当且仅当 ...

  10. 前端中 width 的获取

    这篇文章其实是在了解 viewport 的过程中发现这些概念容易混淆做了个小小的总结.viewport的首要关键是宽度的获取,宽度的计算有下面几个属性和方法: clientWidth offsetWi ...