PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000044. Cân bằng các buồng thí nghiệm (Station Balance)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cân bằng các buồng thí nghiệm (Station Balance)
Station Balance
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are laboratory chambers and specimens with masses . Each chamber holds at most two specimens and may be empty. Let be the mass assigned to chamber and the average chamber mass. The imbalance is . Minimize . The PHOJ Extended version outputs only the imbalance value, unlike the original UVa format, which also lists the contents of each chamber.
Input
- The first line contains : the number of chambers and specimens.
- The second line contains exactly integers , the specimen masses.
Output
Print the minimum imbalance rounded to exactly five digits after the decimal point.
Subtasks
- Subtask 1 (20 points): ; ; for all .
- Subtask 2 (30 points): ; ; for all .
- Subtask 3 (50 points): ; ; for all .
Examples
Input
3 4
5 1 2 7
Output
4.00000
Explanation
The total mass is and , so the average is . Place mass alone in one chamber, alone in another, and together in the third. The chamber totals are , giving imbalance .