- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1710.java
22 lines (20 loc) · 685 Bytes
/
_1710.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
packagecom.fishercoder.solutions.secondthousand;
importjava.util.Arrays;
publicclass_1710 {
publicstaticclassSolution1 {
publicintmaximumUnits(int[][] boxTypes, inttruckSize) {
Arrays.sort(boxTypes, (a, b) -> b[1] - a[1]);
inttotalUnits = 0;
intloadedBoxes = 0;
for (inti = 0; i < boxTypes.length; i++) {
intnumber = boxTypes[i][0];
while (loadedBoxes < truckSize && number > 0) {
totalUnits += boxTypes[i][1];
number--;
loadedBoxes++;
}
}
returntotalUnits;
}
}
}