Skip to content

Commit 63da7b4

Browse files
authored
Update README_EN.md
1 parent 4bb8c0b commit 63da7b4

File tree

1 file changed

+6
-9
lines changed
  • solution/1700-1799/1710.Maximum Units on a Truck

1 file changed

+6
-9
lines changed

solution/1700-1799/1710.Maximum Units on a Truck/README_EN.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,13 @@ func maximumUnits(boxTypes [][]int, truckSize int) (ans int) {
290290

291291
```ts
292292
function maximumUnits(boxTypes: number[][], truckSize: number): number {
293-
const cnt = new Array(1001).fill(0);
294-
for (const [a, b] of boxTypes) {
295-
cnt[b] += a;
296-
}
293+
boxTypes.sort(([_, a], [__, b]) => b - a);
297294
let ans = 0;
298-
for (let b = 1000; b > 0 && truckSize > 0; --b) {
299-
const a = cnt[b];
300-
if (a > 0) {
301-
ans += b * Math.min(truckSize, a);
302-
truckSize -= a;
295+
for (const [count, size] of boxTypes) {
296+
ans += Math.min(truckSize, count) * size;
297+
truckSize -= count;
298+
if (truckSize < 0) {
299+
break;
303300
}
304301
}
305302
return ans;

0 commit comments

Comments
 (0)