#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 返回牛牛最终是从第几个门进入食堂吃饭的
# @param n int整型 代表门的数量
# @param a int整型一维数组 代表每个门外等待的人数
# @return int整型
#
class Solution:
def nowcoderQueue(self , n , a ):
# write code here
arr = []
for i in range(n):
arr.append((a[i],i))
arr.sort()
ans,time = 0,float('inf')
while arr:
t,ind = arr.pop(0)
pos = t%n
t += ind-pos if pos<=ind else n-(pos-ind)
if t<time:
ans = ind
time = t
return ans+1



京公网安备 11010502036488号