PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000051. Trò chuyện trong vòng tròn (Chat in a Circle)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Trò chuyện trong vòng tròn (Chat in a Circle)
Chat in a Circle
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are people with friendliness , arriving one by one and forming a circle. Each new arrival may insert anywhere. The first person receives comfort zero; each later arrival receives the smaller friendliness of the two adjacent people after insertion. Maximize total comfort.
Input
Line 1: . Line 2: friendliness values .
Output
Print the maximum total comfort.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
4
2 2 1 3
Output
7
Explanation
Let friendliness 3 arrive first, then two people with friendliness 2 and the final person with friendliness 1. Appropriate insertions yield comforts 0, 3, 2, 2, totaling 7.