아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Heating Up

시간 제한3초메모리 제한1024 MB

요약
원형 피자에서 조각 하나는 남은 이웃이 최대 하나여야 먹을 수 있다는 규칙 아래, 모든 조각을 먹기 위한 최소 초기 내성을 구한다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 배열
정답자
아직 제출이 없습니다

문제

Jonas just entered his first chilli-eating contest. He is presented with a pizza consisting of nn slices, numbered from 11 to nn, each containing a selection of chilli peppers. Initially slices ii and i+1i+1 are adjacent on the plate (where 1≤i<n1 \leq i < n), and so are slices 11 and nn. According to the contest rules only one slice can be consumed at a time, and the slice must be finished in its entirety before a new slice is started. Jonas is allowed to pick any slice to eat first, but after that he is only allowed to eat slices that have at most one remaining adjacent slice.

The spiciness of each slice is measured in Scoville Heat Units (SHU). Jonas has a certain spiciness tolerance, also measured in SHU, which corresponds to the spiciness of the spiciest slice that Jonas can tolerate eating. He has also noticed that, after eating a slice of kk SHU, his tolerance immediately increases by kk.

In order to win the contest, Jonas would like to finish all the slices of his pizza. Help him determine the minimum initial spiciness tolerance necessary to do so while abiding by the contest rules.

입력

The input consists of:

  • One line with an integer nn (3≤n≤5⋅1053 \le n \le 5 \cdot 10^{5}), the number of pizza slices.
  • One line with nn integers s_1,s_2,…,s_ns\_{1}, s\_{2}, \ldots, s\_{n} (0≤s_i≤10130 \le s\_{i} \le 10^{13}), where s_is\_i is the spiciness of the iith slice in SHU.

출력

Output the minimum initial spiciness tolerance in SHU that Jonas needs in order to be able to eat all slices of the pizza.

예제2

  1. 예제 1

    입력
    5
    5 0 10 6 1
    
    예상 출력
    4
    
  2. 예제 2

    입력
    7
    20 23 7 2 3 7 1
    
    예상 출력
    2