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. Yii2系列教程三:Database And Gii

    上一篇文章我们理了一下Yii2的MVC,Forms和Layouts,这篇文章就直接按照约定来说说Yii2与数据库相关的一些事情,如果你觉得不够的话,不急,更具体的用法我会在后续的教程给出,并且这里也会 ...

  2. Lucene分词器

    Lucene分析器的基类为Analyzer,Analyzer包含两个核心组件:Tokenizer和 TokenFilter.自定义分析器必须实现Analyzer类的抽象方法createComponen ...

  3. Mybatis学习记录(二)----mybatis开发dao的方法

    1  SqlSession使用范围 1.1 SqlSessionFactoryBuilder 通过SqlSessionFactoryBuilder创建会话工厂SqlSessionFactory 将Sq ...

  4. 插件化注解处理API(Pluggable Annotation Processing API)

    Java奇技淫巧-插件化注解处理API(Pluggable Annotation Processing API) 参考资料 JDK6的新特性之六:插入式注解处理API(Pluggable Annota ...

  5. rsync问题-connection refused(111)、Unknown module

    1.Connection refused (111) 启动服务:rsync --daemon --config=/etc/rsyncd.conf 2.@ERROR: Unknown module 's ...

  6. 【BIEE】12_查看BIEE的物理SQL

    有时候,我们在使用BIEE的时候回出现一些问题,需要借助物理SQL来进行问题分析.通过物理SQL我们就可以看到BIEE在数据库中是如何去检索出数据库. 查看物理SQL的方式 [登录BIEE]--[管理 ...

  7. WSDL接口数据传递以及外网发布需要注意的地方

    A系统传递数据给B系统 1.A创建asmx推送接口如下 using System; using System.Collection.Generic; using System.Data; using ...

  8. css学习之overlay

    CSS Overlay技巧 作者:大漠 日期:2013-11-10 点击:8  本文由大漠根据SARA SOUEIDAN的<CSS OVERLAY TECHNIQUES>所译,整个译文带 ...

  9. 8.1.3 在BroadcastReceiver中启动Service

    2010-06-21 16:57 李宁 中国水利水电出版社 字号:T | T <Android/OPhone开发完全讲义>第8章Android服务,本章主要介绍了Android系统 中的服 ...

  10. PV、UV、GMV

    原文地址:电商术语:客单价.UV.PV.转化率.销售额作者:馨闻莲博 UV(独立访客):Unique Visitor,访问您网站的一台电脑客户端为一个访客.00:00-24:00内相同的客户端只会被计 ...