CF982D.Shark

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn 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 kk that if the shark in some day traveled the distance strictly less than kk, then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to kk; 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 kk.

The shark never returned to the same location after it has moved from it. Thus, in the sequence of nn days we can find consecutive nonempty segments when the shark traveled the distance less than kk in each of the days: each such segment corresponds to one location. Max wants to choose such kk that the lengths of all such segments are equal.

Find such integer kk, that the number of locations is as large as possible. If there are several such kk, print the smallest one.

长期以来,科学家们一直在研究鲨鱼的行为。与其他许多物种一样,鲨鱼会在某个地点进行短距离移动,然后在不同地点之间进行长距离移动。

马克斯是一名年轻的生物学家。他连续观察了某条鲨鱼 nn 天,并记录下了鲨鱼每天所游过的距离。所有这些距离互不相同。现在,马克斯希望推断出这条鲨鱼一共访问了多少个不同的地点。他假设存在一个整数 kk,使得:若鲨鱼某天游过的距离严格小于 kk,则它当天没有更换地点;反之,若某天游过的距离大于等于 kk,则它当天更换了地点。注意,鲨鱼有可能连续多天都在更换地点,即这些天中每天游过的距离均至少为 kk。

此外,鲨鱼一旦离开某个地点,就永远不会返回该地点。因此,在这 nn 天的序列中,我们可以找出若干段非空的连续区间,其中每一段内每一天鲨鱼游过的距离都小于 kk;每一段这样的区间对应鲨鱼停留的一个地点。马克斯希望选择一个 kk,使得所有这些区间的长度都相等。

请找出满足上述条件的整数 kk,使得鲨鱼访问的地点数量尽可能多。如果有多个这样的 kk,输出其中最小的一个。

输入格式

The first line contains a single integer nn (1≤n≤1051 \leq n \leq 10^5) — the number of days.

The second line contains nn distinct positive integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the distance traveled in each of the day.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 表示天数。

第二行包含 nn 个互不相同的正整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 表示每天行驶的距离。

输出格式

Print a single integer kk, 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. kk is smallest possible satisfying the first and second conditions.

输出一个整数 kk,使得:

  1. 鲨鱼在每个位置停留的天数相同;
  2. 在满足第一条条件的前提下,位置的数量尽可能多;
  3. 在满足第一条和第二条条件的前提下,kk 尽可能小。

输入输出样例

  • 输入#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 11 and 22 (first location), then on 44-th and 55-th days (second location), then on 77-th and 88-th days (third location). There are three locations in total.

In the second example the shark only moves inside a location on the 22-nd day, so there is only one location.

在第一个例子中,鲨鱼在第 11 天和第 22 天(第一个位置)、第 44 天和第 55 天(第二个位置)、第 77 天和第 88 天(第三个位置)分别停留在某一位置内。总共有三个位置。

在第二个例子中,鲨鱼仅在第 22 天停留在某一位置内,因此只有一个位置。

输入解题思路,AI测评打分。不知道怎么写?

首页