PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000111. Những thùng gỗ của Liebig (Liebig's Barrels)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Những thùng gỗ của Liebig (Liebig's Barrels)
Liebig's Barrels
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are wooden staves of lengths . Partition all staves into exactly barrels, each containing staves. Barrel volume equals the shortest stave in that barrel. All barrel volumes must differ by at most . Maximize their total or output if impossible.
Input
Line 1 contains . Line 2 contains integers .
Output
Print the maximum total barrel volume, or if no valid partition exists.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
4 2 1
2 2 1 2 3 2 2 3
Output
7
Explanation
Sort lengths to . Four barrels can have minimum staves , giving volume ; all differ by at most , and no higher total is possible.