A9483 | Jzzhu and Children
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted