-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWoodcuttingv3.java
59 lines (47 loc) · 1.89 KB
/
Woodcuttingv3.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Errors made: make sure that the variable primitive type value range is within the range of the given primitive type, aka using long
instead of int for large ranges of values */
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Woodcuttingv3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
sc.nextLine();
for (int x = 0; x < testCases; x++) {
int customers = sc.nextInt();
sc.nextLine();
ArrayList<Long> cmwoodTU = new ArrayList<>();
for (int y = 0; y < customers; y++) {
int woodNum = sc.nextInt();
int[] woodsz = new int[woodNum];
for (int z = 0; z < woodNum; z++) {
int woodSize = sc.nextInt();
woodsz[z] = woodSize;
}
long woodTU = 0;
for (long TU : woodsz) {
woodTU += TU;
}
cmwoodTU.add(woodTU);
sc.nextLine();
}
Collections.sort(cmwoodTU);
//System.out.println(cmwoodTU.get(0));
ArrayList<Long> cmMinOrderTU = new ArrayList<>();
long minTU = 0;
for (int cmindex = 0; cmindex < customers; cmindex++) {
minTU += cmwoodTU.get(cmindex);
cmMinOrderTU.add(cmindex, minTU);
}
long totalcumulativeTU = 0;
for (long TU : cmMinOrderTU) {
totalcumulativeTU += TU;
}
// System.out.println(totalcumulativeTU);
double minAvgTU = (double) totalcumulativeTU / (double) customers;
System.out.printf("%.7f", minAvgTU);
System.out.println();
}
}
}