As the Formula One Grand Prix was approaching, the officials decided to make the races a…
- User
As the Formula One Grand Prix was approaching, the officials decided to make the races a little more interesting with a new set of rules. According to the new set of rules, each driver will be given a vehicle with different height and the driver with maximum SIGHT would win the race.
Now, SIGHT of a driver is defined by ( X * P ) % 1000000007, where
X = number of drivers he can see in front of him + number of drivers he can see behind him P = position of the driver in a given scenario ( index of the driver array is 1-N indexed )
As all the drivers are moving in a straight line, a driver i cannot see beyond another driver j if height of j ≥ height of driver i. INPUT First line of the input contains t, the number of test cases. The 1st line of each test case consists of a single integer n, the number of drivers. Second line contains n space separated integers H[1], H[2], H[3]...H[n] denoting the heights of the drivers 1, 2, 3....n.
OUTPUT Output for each test case should be a single line displaying the index of the winning driver. In case of ties, display the driver with minimum index.
CONSTRAINTS 0 ≤ t ≤ 50 1 ≤ n ≤ 10 ^ 5 0 ≤ H[i] ≤ 10 ^ 6
SAMPLE INPUT 2 5 4 1 2 1 4 5 5 1 2 4 1
SAMPLE OUTPUT 5 4
Assistant
pythonMOD = 10**9 + 7 def main(): import sys input = sys.stdin.read().split() ptr = 0 t = int(input[ptr]) ptr += 1 for _ in range(t): n = int(input[ptr]) ptr += 1 H = list(map(int, input[ptr:ptr+n])) ptr += n previous_ge = [-1] * n stack = [] for i in range(n): while stack and H[stack[-1]] < H[i]: stack.pop() if stack: previous_ge[i] = stack[-1] stack.append(i) next_ge = [n] * n stack = [] for i in range(n-1, -1, -1): while stack and H[stack[-1]] < H[i]: stack.pop() if stack: next_ge[i] = stack[-1] stack.append(i) max_sight = -1 winner = -1 for i in range(n): if previous_ge[i] == -1: lc = i else: lc = i - previous_ge[i] - 1 rc = next_ge[i] - i - 1 x = lc + rc sight = (x * (i + 1)) % MOD if sight > max_sight or (sight == max_sight and (i + 1) < winner): max_sight = sight winner = i + 1 print(winner) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.