PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000098. Sơn các tấm vải (Canvas Painting)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Sơn các tấm vải (Canvas Painting)
Canvas Painting
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
All canvases initially have the same color; canvas has size . In one operation a same-colored group is divided into two nonempty groups, each repainted a different fresh color. The amount of paint is the total size of all canvases repainted. Make all canvases have distinct colors using minimum paint.
Input
Line 1 contains . Line 2 contains the integer canvas sizes.
Output
Print the minimum total amount of paint.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
3
7 4 7
Output
29
Explanation
Merge sizes and at cost , then merge and at cost . The total paint is .