A11849 | Shark
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.
Max is a young biologist. For $n$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer $k$ that if the shark in some day traveled the distance strictly less than $k$ , then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to $k$ ; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least $k$ .
The shark never returned to the same location after it has moved from it. Thus, in the sequence of $n$ days we can find consecutive nonempty segments when the shark traveled the distance less than $k$ in each of the days: each such segment corresponds to one location. Max wants to choose such $k$ that the lengths of all such segments are equal.
Find such integer $k$ , that the number of locations is as large as possible. If there are several such $k$ , print the smallest one.
Max is a young biologist. For $n$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer $k$ that if the shark in some day traveled the distance strictly less than $k$ , then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to $k$ ; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least $k$ .
The shark never returned to the same location after it has moved from it. Thus, in the sequence of $n$ days we can find consecutive nonempty segments when the shark traveled the distance less than $k$ in each of the days: each such segment corresponds to one location. Max wants to choose such $k$ that the lengths of all such segments are equal.
Find such integer $k$ , that the number of locations is as large as possible. If there are several such $k$ , print the smallest one.
输入格式
The first line contains a single integer $n$ ( $1 \leq n \leq 10^5$ ) — the number of days.
The second line contains $n$ distinct positive integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ) — the distance traveled in each of the day.
The second line contains $n$ distinct positive integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ) — the distance traveled in each of the day.
输出格式
Print a single integer $k$ , such that
1. the shark was in each location the same number of days,
2. the number of locations is maximum possible satisfying the first condition,
3. $k$ is smallest possible satisfying the first and second conditions.
1. the shark was in each location the same number of days,
2. the number of locations is maximum possible satisfying the first condition,
3. $k$ is smallest possible satisfying the first and second conditions.
输入输出样例
输入 #1
8 1 2 7 3 4 8 5 6
输出 #1
7
输入 #2
6 25 1 2 3 14 36
输出 #2
2
In the first example the shark travels inside a location on days $1$ and $2$ (first location), then on $4$ -th and $5$ -th days (second location), then on $7$ -th and $8$ -th days (third location). There are three locations in total.
In the second example the shark only moves inside a location on the $2$ -nd day, so there is only one location.
In the second example the shark only moves inside a location on the $2$ -nd day, so there is only one location.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted