KillCode's Wish
Practice
3.5 (11 votes)
Easy
Problem
66% Success 3247 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
18 votes
Tags:
Ad-HocEasyImplementation
Points:20
27 votes
Tags:
ApprovedBasic ProgrammingEasyOpen
Points:20
71 votes
Tags:
Ad-HocApprovedEasyImplementationOpenReadySorting
Editorial

No editorial available for this problem.