PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000095. Cắt bánh mì (Bread)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cắt bánh mì (Bread)
Bread
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A loaf has length . Each of recipients needs one piece of length . Cutting a piece of integer length into two positive pieces costs . Unused bread is allowed. Find the minimum cutting cost.
Input
The first line contains ; the next contains requested lengths .
Output
Print the minimum total cutting cost.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5 7
1 2 1 2 1
Output
16
Explanation
Cut into and (cost ), into and (cost ), into and (cost ), and one into two s (cost ). Total .