Description

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 Input

Input
5 2
1 3 1 4 2
Output
4
Input
6 4
1 1 2 2 3 3
Output
6

Hint

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.


//队列

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue> using namespace std; struct node
{
int a,b;
} p,t;
int main()
{
queue<node> q;
int n,m;
while(~scanf("%d%d",&n,&m))
{
int top=-1;
for(int i=0; i<n; i++)
{
scanf("%d",&p.a);
p.b=i+1;
if(p.a-m>0)
{
p.a-=m;
q.push(p);
top=p.b;
}
}
// t=q.top();
// printf("%d\n",t.a);
if(top==-1)
printf("%d\n",n);
else
{
while(!q.empty())
{
t=q.front();
q.pop();
if(t.a-m>0)
{
t.a-=m;
q.push(t);
top=t.b;
}
}
printf("%d\n",top);
} }
}

CodeForces 450A 队列的更多相关文章

  1. codeforces 704A (队列模拟) Thor

    题目:这里 题意:n个app,q个操作,当操作数type为1的时候表示y这个app推送了你一条消息,当操作数type为2的时候表示将y这个app已推送的所有消息都读完,当操作数为3的时候 表示将已经推 ...

  2. CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列

    B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...

  3. Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列

    B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/p ...

  4. CodeForces 546C(队列)

    CodeForces 546C Soldier and Cards Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I ...

  5. Codeforces Beta Round #6 (Div. 2 Only) 单调队列

    题目链接: http://codeforces.com/contest/6/problem/E E. Exposition time limit per test 1.5 secondsmemory ...

  6. Codeforces 445A Boredom(DP+单调队列优化)

    题目链接:http://codeforces.com/problemset/problem/455/A 题目大意:有n个数,每次可以选择删除一个值为x的数,然后值为x-1,x+1的数也都会被删除,你可 ...

  7. Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列

    题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...

  8. Codeforces 1029B. Creating the Contest 动态规划O(nlogn)解法 及 单调队列O(n)解法

    题目链接:http://codeforces.com/problemset/problem/1029/B 题目大意:从数组a中选出一些数组成数组b,要求 b[i+1]<=b[i]*2 . 一开始 ...

  9. Codeforces 940 E.Cashback (单调队列,dp)

    Codeforces 940 E.Cashback 题意:一组数,要分为若干个区间,每个区间长度为ki(1<=ki<=n),并且对于每个区间删去前ki/c(向下取整)个小的数(即对区间升序 ...

随机推荐

  1. iOS开发- 自己主动消失的弹出框

    - (void)timerFireMethod:(NSTimer*)theTimer//弹出框 { UIAlertView *promptAlert = (UIAlertView*)[theTimer ...

  2. Python——Code Like a Pythonista: Idiomatic Python

    Code Like a Pythonista: Idiomatic Python 如果你有C++基础,那学习另一门语言会相对容易.因为C++即面向过程,又面向对象.它很底层,能像C一样访问机器:它也很 ...

  3. dubbo笔记

    使用Maven打包依赖项,启动时从本地jar中读取dubbo.xsd 最近项目用到dubbo,打包启动时报错 Failed to read schema document from http://co ...

  4. MySQL错误Another MySQL daemon already running with the same unix socket.v

    etc/init.d/mysqld start 结果显示 Another MySQL daemon already running with the same unix socket.显示另一个MyS ...

  5. BIEE-CSS样式大全

    字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD 样式 {font-style: obl ...

  6. 《深入PHP:面向对象、模式与实践》(一)

    第1章  PHP:设计与管理 本章主要介绍了本书有哪些内容. 第2章  PHP与对象 本章总结了PHP面向对象特性的发展过程,逐步介绍对象的概念. PHP/FI:支持变量.关联数组和函数.没有对象. ...

  7. Flume、Kafka、Storm结合

    Todo: 对Flume的sink进行重构,调用kafka的消费生产者(producer)发送消息; 在Sotrm的spout中继承IRichSpout接口,调用kafka的消息消费者(Consume ...

  8. ibatis中<![CDATA[使用解释

    http://hi.baidu.com/taoxincheng0/blog/item/3916c4ec413f03c22e2e2160.html ibatis中什么时候需要用到: <![CDAT ...

  9. 二维数组,锯齿数组和集合 C# 一维数组、二维数组(矩形数组)、交错数组(锯齿数组)的使用 C# 数组、多维数组(矩形数组)、锯齿数组(交叉数组)

    二维数组,锯齿数组和集合 一.二维数组 二维数组:一维数组----豆角二维数组----表格 定义:1.一维数组:数据类型[] 数组变量名 = new 数据类型[数组长度];数据类型[] 数组变量名 = ...

  10. MvcPager帮助文档 - MvcAjaxOptions 类

    表示用于 MvcPager 在 Ajax 分页模式下的选项设置,该类继承自 AjaxOptions. 公共属性: 名称 说明 默认值 AllowCache 获取或设置一个值,该值指示是否在Ajax分页 ...