package leetcode;

/**
 * https://leetcode.com/problems/maximum-units-on-a-truck/
 */
public class Problem1710 {
    public int maximumUnits(int[][] boxTypes, int truckSize) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1710 prob = new Problem1710();
        System.out.println(prob.maximumUnits(new int[][]{
            {1,3},{2,2},{3,1}
        }, 3)); // 8
        System.out.println(prob.maximumUnits(new int[][]{
            {5,10},{2,5},{4,7},{3,9}
        }, 10)); // 91
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -207,358 +207,510 @@
     
-// TODO%0A        return 0
+Arrays.sort(boxTypes, (a, b) -%3E Integer.compare(b%5B1%5D, a%5B1%5D));%0A        int nBoxes = truckSize
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1710 prob = new Problem1710();%0A        System.out.println(prob.maximumUnits(new int%5B%5D%5B%5D%7B%0A            %7B1,3%7D,%7B2,2%7D,%7B3,1%7D%0A        %7D, 3)); // 8%0A        System.out.println(prob.maximumUnits(new int%5B%5D%5B%5D%7B%0A            %7B5,10%7D,%7B2,5%7D,%7B4,7%7D,%7B3,9%7D%0A        %7D, 10)); // 91
+int answer = 0;%0A        for (int%5B%5D boxType : boxTypes) %7B%0A            if (nBoxes - boxType%5B0%5D %3E= 0) %7B%0A                answer += boxType%5B0%5D * boxType%5B1%5D;%0A                nBoxes -= boxType%5B0%5D;%0A            %7D else %7B%0A                answer += nBoxes * boxType%5B1%5D;%0A                nBoxes = 0;%0A            %7D%0A            if (nBoxes == 0) %7B%0A                break;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1710