N people are standing in a line. Lets number them from 1 to n and ith person is standing at ith position in line. We are distributing hats to them. ith person wants at least a[i] hats. We are following some rules for distribution -
- Give m hats to first person of the line. - If this person still haven't got enough hats, then he goes to end of the line. - Repeat the first two steps while the line is not empty.
You need to find who will be the last one to get hats i.e. the number of last person ?
1 <= n, m, a[i] <= 100
Input format :
Line 1 : Integer N (Total no. of people) and m
Line 2 : N integers (separated by space), specifying a[i] for each person
Note : Numbering of person starts form 1.
Sample Input 1 :
5 2 1 3 1 4 2
Sample Output 1 :
Sample Input 2 :
6 4 1 1 2 2 3 3
Sample Output 2 :
Login to submit your solution