#P15813. [JOI 2014 Final] バームクーヘン

    ID: 17879 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2014二分JOI(日本)

[JOI 2014 Final] バームクーヘン

Problem Description

JOI is planning to eat some sweets with his two younger sisters, JOI-ko and JOI-mi. Today’s sweet is their favorite: an annual ring cake (Baumkuchen).

An annual ring cake is a cylindrical sweet as shown in the figure below. To divide it among three people, JOI must make three cuts along the radial direction, splitting it into three pieces. However, this cake is as hard as real wood, so cutting it is not easy. Therefore, the cake already has NN notches, and JOI can only cut at positions where there is a notch. The notches are numbered clockwise from 11 to NN. For 1≤i≤N−11 \le i \le N-1, the size of the part between notch ii and notch i+1i+1 is AiA_i. Also, the size of the part between notch NN and notch 11 is ANA_N.

:::align{center}

Figure 1: Example of an annual ring cake where N=6N = 6, A1=1A_1 = 1, A2=5A_2 = 5, A3=4A_3 = 4, A4=5A_4 = 5, A5=2A_5 = 2, A6=4A_6 = 4 :::

Being considerate of his sisters, after cutting the cake into three pieces, JOI decides that he will take the smallest piece, and give the remaining two pieces to his two sisters. On the other hand, JOI loves Baumkuchen very much, so he wants to eat as much as possible. If he cuts the cake in a way that makes the smallest piece as large as possible, what will be the size of the piece that JOI eats?

Task

Given the number of notches NN and the integers A1,…,ANA_1, \dots, A_N representing the sizes of the parts, write a program to output the maximum possible value of the smallest piece size when the annual ring cake is cut into three pieces.

Input Format

Read the following data from standard input.

  • Line 1 contains an integer NN, indicating that there are NN notches on the annual ring cake.
  • In the next NN lines, line ii (1≤i≤N1 \le i \le N) contains an integer AiA_i, indicating that the size of the part between notch ii and notch i+1i+1 (when i=Ni = N, between notch NN and notch 11) is AiA_i.

Output Format

Output one line to standard output containing one integer: the maximum possible value of the smallest piece size when the annual ring cake is cut into three pieces.

6
1
5
4
5
2
4
6
30
1
34
44
13
30
1
9
3
7
7
20
12
2
44
6
9
44
31
17
20
33
18
48
23
19
31
24
50
43
15
213

Hint

Sample Explanation

:::align{center}

Figure 2: It is optimal to cut at notches 11, 33, and 55. :::

Constraints

All input data satisfy the following conditions.

  • 3≤N≤1053 \le N \le 10^5
  • 1≤Ai≤1091 \le A_i \le 10^9 (1≤i≤N1 \le i \le N)

Subtasks

Subtask 1 [5 points]

N≤100N \le 100.

Subtask 2 [15 points]

N≤400N \le 400.

Subtask 3 [30 points]

N≤8000N \le 8000.

Subtask 4 [50 points]

No additional constraints.


Translation completed by DeepSeek V3.2.

Translated by ChatGPT 5