302335: CF450A. Jzzhu and Children

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Jzzhu and Children

题意翻译

题目描述 `Jzzhu`给学校里的$n$个孩子发糖果,编号从$1$到$n$排成一队,第$i$个孩子想得到至少$a_i$个糖果。 `Jzzhu`的操作如下: - 给队首的孩子$m$个糖果 - 如果这个孩子已经得到满足,他就会回家,否则他会到队尾。 - 在队列非空时重复上述两个操作 在满足上述条件的情况下,求出最后回家的孩子的编号 输入格式 第一行两个整数$n,m(1\leq n,m\leq100)$,第二行$n$个整数$a_1,a_2,\cdots,a_n(\forall a_i\in[1,100])$ 输出格式 输出一个整数表示最后回家的孩子的编号

题目描述

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 $ a_{i} $ 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?

输入输出格式

输入格式


The first line contains two integers $ n,m $ $ (1<=n<=100; 1<=m<=100) $ . The second line contains $ n $ integers $ a_{1},a_{2},...,a_{n} $ $ (1<=a_{i}<=100) $ .

输出格式


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

输入输出样例

输入样例 #1

5 2
1 3 1 4 2

输出样例 #1

4

输入样例 #2

6 4
1 1 2 2 3 3

输出样例 #2

6

说明

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.

Input

题意翻译

题目描述 `Jzzhu`给学校里的$n$个孩子发糖果,编号从$1$到$n$排成一队,第$i$个孩子想得到至少$a_i$个糖果。 `Jzzhu`的操作如下: - 给队首的孩子$m$个糖果 - 如果这个孩子已经得到满足,他就会回家,否则他会到队尾。 - 在队列非空时重复上述两个操作 在满足上述条件的情况下,求出最后回家的孩子的编号 输入格式 第一行两个整数$n,m(1\leq n,m\leq100)$,第二行$n$个整数$a_1,a_2,\cdots,a_n(\forall a_i\in[1,100])$ 输出格式 输出一个整数表示最后回家的孩子的编号

加入题单

上一题 下一题 算法标签: