time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There are nn piranhas with sizes a1,a2,…,ana1,a2,…,an in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
When the piranha ii eats some piranha, its size increases by one (aiai becomes ai+1ai+1).
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
For example, if a=[5,3,4,4,5]a=[5,3,4,4,5], then the third piranha can be dominant. Consider the sequence of its moves:
You have to answer tt independent test cases.
Input
The first line of the input contains one integer tt (1≤t≤2⋅1041≤t≤2⋅104) — the number of test cases. Then tt test cases follow.
The first line of the test case contains one integer nn (2≤n≤3⋅1052≤n≤3⋅105) — the number of piranhas in the aquarium. The second line of the test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the size of the ii-th piranha.
It is guaranteed that the sum of nn does not exceed 3⋅1053⋅105 (∑n≤3⋅105∑n≤3⋅105).
Output
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
Example
input
Copy
6 5 5 3 4 4 5 3 1 1 1 5 4 4 3 4 4 5 5 5 4 3 2 3 1 1 2 5 5 4 3 5 5
output
Copy
3 -1 4 3 3 1
Note
The first test case of the example is described in the problem statement.
In the second test case of the example, there are no dominant piranhas in the aquarium.
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4,4,5,4][4,4,5,4], then it can eat any other piranha in the aquarium.
解题说明:此题是一道模拟题,根据题目意思进行遍历找序列中最大的,如果满足有一个最大的数旁边存在比它小的数,那么必然能找到满足条件的情况,输出这个数位置即可。如果不能满足就是-1.
#include<bits/stdc++.h>
using namespace std;
int t, n, a[300030];
int main()
{
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
a[0] = a[1];
a[n + 1] = a[n];
int ans = -1, max = 0;
for (int i = 1; i <= n; i++)
{
if (a[i]>max && (a[i]>a[i - 1] || a[i]>a[i + 1]))
{
ans = i;
max = a[i];
}
}
cout << ans << endl;
}
return 0;
}