Problems > Twice as Large

Twice as Large

Difficulty: 1000 3000 ms 128 MB

implementation

The maximum is unique. Print its 1-based position if it is at least TWICE every other element, else −1.

Input: the first line has N; the second line has N integers with a unique maximum.

Output: the dominant index, or −1.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ ai ≤ 109

Sample Tests

Input 1
4
3 6 1 0
Output 1
2
Input 2
4
1 2 3 4
Output 2
-1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.