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

Bài tập thuộc lộ trình

2 lộ trình

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 CC laboratory chambers and SS specimens with masses m1,…,mSm_1,\ldots,m_S. Each chamber holds at most two specimens and may be empty. Let XiX_i be the mass assigned to chamber ii and A=(m1+⋯+mS)/CA=(m_1+\cdots+m_S)/C the average chamber mass. The imbalance is I=∑i=1C∣Xi−A∣I=\sum_{i=1}^{C}|X_i-A|. Minimize II. 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 C,SC,S: the number of chambers and specimens.
  • The second line contains exactly SS integers m1,…,mSm_1,\ldots,m_S, the specimen masses.

Output

Print the minimum imbalance rounded to exactly five digits after the decimal point.

Subtasks

  • Subtask 1 (20 points): 1≤C≤21\le C\le2; 1≤S≤2C1\le S\le2C; 1≤mi≤10001\le m_i\le1000 for all 1≤i≤S1\le i\le S.
  • Subtask 2 (30 points): 1≤C≤31\le C\le3; 1≤S≤2C1\le S\le2C; 1≤mi≤10001\le m_i\le1000 for all 1≤i≤S1\le i\le S.
  • Subtask 3 (50 points): 1≤C≤51\le C\le5; 1≤S≤2C1\le S\le2C; 1≤mi≤10001\le m_i\le1000 for all 1≤i≤S1\le i\le S.

Examples

Input

3 4
5 1 2 7

Output

4.00000

Explanation

The total mass is 1515 and C=3C=3, so the average is A=5A=5. Place mass 77 alone in one chamber, 55 alone in another, and 1,21,2 together in the third. The chamber totals are 7,5,37,5,3, giving imbalance ∣7−5∣+∣5−5∣+∣3−5∣=4|7-5|+|5-5|+|3-5|=4.