-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathUVa00410_StationBalance.java
42 lines (37 loc) · 1.33 KB
/
UVa00410_StationBalance.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 351 (410 - Station Balance) */
/* SUBMISSION: 08912828 */
/* SUBMISSION TIME: 2011-06-02 14:02:26 */
/* LANGUAGE: 2 */
import java.util.*;
public class UVa00410_StationBalance {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int cnt = 0;
while (in.hasNextInt()) {
++cnt;
int C = in.nextInt();
int S = in.nextInt();
double AM = 0.0;
double imbalance = 0.0;
int[] sorted = new int[2 * C];
for (int i = 0; i < S; ++i) {
sorted[i] = in.nextInt();
AM += sorted[i];
}
Arrays.sort(sorted);
AM /= C;
System.out.println("Set #" + cnt);
int k = 0;
for (int i = 2 * C - 1; i >= C; --i) {
System.out.println(" " + k + ":" + (sorted[i] != 0 ? " " + sorted[i] : "") +
(sorted[2 * C - 1 -i] != 0 ? " " + sorted[2 * C - 1 - i] : ""));
double mass = sorted[i] + sorted[2 * C - 1 - i];
imbalance += Math.abs(mass - AM);
++k;
}
System.out.printf(Locale.ENGLISH, "IMBALANCE = %.5f%n%n", imbalance);
}
}
}