CF450A.Jzzhu and Children

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

Jzzhu 的学校里有 nn 个孩子。Jzzhu 打算给他们分发一些糖果。我们把所有孩子从 11 到 nn 编号。第 ii 个孩子至少想要得到 aia_i 颗糖果。

Jzzhu 让孩子们排成一队。初始时,第 ii 个孩子站在队伍的第 ii 个位置。接着 Jzzhu 开始分发糖果,遵循如下算法:

  1. 给队伍最前面的孩子 mm 颗糖果;
  2. 若该孩子仍未获得足够糖果(即已得糖果数仍少于 aia_i),则该孩子移到队伍末尾;否则该孩子直接回家;
  3. 当队伍非空时,重复执行上述两个步骤。

考虑所有孩子按回家顺序所构成的序列。Jzzhu 想知道:在这个序列中,最后一个回家的是哪个孩子?

输入格式

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).

第一行包含两个整数 nn 和 mm(1≤n≤1001 \leq n \leq 100;1≤m≤1001 \leq m \leq 100)。第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1001 \leq a_i \leq 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.

我们来考虑第一个样例。

首先,儿童 1 得到 2 颗糖果后回家。接着,儿童 2 得到 2 颗糖果,然后排到队尾。此时队伍为 [3, 4, 5, 2](按队伍顺序排列的儿童编号)。接着,儿童 3 得到 2 颗糖果后回家;随后,儿童 4 得到 2 颗糖果,然后排到队尾。此时队伍为 [5, 2, 4]。然后,儿童 5 得到 2 颗糖果后回家。接着,儿童 2 得到 2 颗糖果后回家,最后,儿童 4 得到 2 颗糖果后回家。

儿童 4 是最后一个回家的。

输入解题思路,AI测评打分。不知道怎么写?

首页