A13777 | Dominant Piranha
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ piranhas with sizes $a_1, a_2, \ldots, a_n$ 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:
- The piranha $i$ can eat the piranha $i-1$ if the piranha $i-1$ exists and $a_{i - 1} < a_i$ .
- The piranha $i$ can eat the piranha $i+1$ if the piranha $i+1$ exists and $a_{i + 1} < a_i$ .
When the piranha $i$ eats some piranha, its size increases by one ( $a_i$ becomes $a_i + 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]$ , then the third piranha can be dominant. Consider the sequence of its moves:
- The piranha eats the second piranha and $a$ becomes $[5, \underline{5}, 4, 5]$ (the underlined piranha is our candidate).
- The piranha eats the third piranha and $a$ becomes $[5, \underline{6}, 5]$ .
- The piranha eats the first piranha and $a$ becomes $[\underline{7}, 5]$ .
- The piranha eats the second piranha and $a$ becomes $[\underline{8}]$ .
You have to answer $t$ independent test cases.
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:
- The piranha $i$ can eat the piranha $i-1$ if the piranha $i-1$ exists and $a_{i - 1} < a_i$ .
- The piranha $i$ can eat the piranha $i+1$ if the piranha $i+1$ exists and $a_{i + 1} < a_i$ .
When the piranha $i$ eats some piranha, its size increases by one ( $a_i$ becomes $a_i + 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]$ , then the third piranha can be dominant. Consider the sequence of its moves:
- The piranha eats the second piranha and $a$ becomes $[5, \underline{5}, 4, 5]$ (the underlined piranha is our candidate).
- The piranha eats the third piranha and $a$ becomes $[5, \underline{6}, 5]$ .
- The piranha eats the first piranha and $a$ becomes $[\underline{7}, 5]$ .
- The piranha eats the second piranha and $a$ becomes $[\underline{8}]$ .
You have to answer $t$ independent test cases.
输入格式
The first line of the input contains one integer $t$ ( $1 \le t \le 2 \cdot 10^4$ ) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ( $2 \le n \le 3 \cdot 10^5$ ) — the number of piranhas in the aquarium. The second line of the test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the size of the $i$ -th piranha.
It is guaranteed that the sum of $n$ does not exceed $3 \cdot 10^5$ ( $\sum n \le 3 \cdot 10^5$ ).
The first line of the test case contains one integer $n$ ( $2 \le n \le 3 \cdot 10^5$ ) — the number of piranhas in the aquarium. The second line of the test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the size of the $i$ -th piranha.
It is guaranteed that the sum of $n$ does not exceed $3 \cdot 10^5$ ( $\sum n \le 3 \cdot 10^5$ ).
输出格式
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.
输入输出样例
输入 #1
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
输出 #1
3 -1 4 3 3 1
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]$ , then it can eat any other piranha in the aquarium.
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]$ , then it can eat any other piranha in the aquarium.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted