KillCode's Wish

3.5

11 votes
Easy
Problem

KillCode is very thrilled to have won unlimited ladoos in a programming competition . But being a generous programmer he decided to give away all his ladoos to small children. Now there are n children standing in a queue where a[i] denotes the hunger of ith child. KillCode can give maximum of M ladoos to a child at a time. Now there are 2 conditions :

1- If a child gets equal to or more ladoos than his hunger , then he will return back to his home.

2- If a child gets less ladoos , he will take m ladoos and will move to last in the queue to get his turn again.

Constraints :

1<=n,m<=10000

1<=a[i]<=10000000

Input:

The first line contain integer t denoting the test cases , next t line follows : Now you will be given N,M . Next line will contain n space separated integers .

Output:

Output the index of child who will remain last in the queue.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?