All Tracks Basic Programming Implementation Basics of Implementation Problem

KillCode's Wish
Tag(s):

Easy

Problem
Editorial
Analytics

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.

SAMPLE INPUT
2
5 2
1 3 1 4 2
6 4
1 1 2 2 3 3
SAMPLE OUTPUT
4
6
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications