#GD0000188. Hai người cùng đọc sách (Reading Books)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hai người cùng đọc sách (Reading Books)
Reading Books
Source: CSES
Version: Phuoc Hung OJ (single-case adaptation where applicable)
Problem Statement
There are books, book requiring time units to read completely. Two readers must each read every book. They cannot read the same book simultaneously, and each person reads at most one book at a time; the orders may differ. Find the earliest time by which both finish.
Input
The first line contains ; the next line contains positive integers .
Output
Print the minimum total time.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Example 1
Input
3
2 8 3
Output
16
Explanation
The sum of all reading times is 13, but the longest book takes 8 units and must be read by both people at separate times. Hence at least 16 units are needed, and a schedule achieving 16 exists.
Example 2
Input
4
1 2 3 4
Output
10
Explanation
The sum is 10 and twice the longest time is 8. By interleaving the orders, both readers can finish after exactly 10 units.