package leetcode;

/**
 * https://leetcode.com/problems/boats-to-save-people/
 */
public class Problem881 {
    public int numRescueBoats(int[] people, int limit) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem881 prob = new Problem881();
        System.out.println(prob.numRescueBoats(new int[]{1, 2}, 3)); // 1
        System.out.println(prob.numRescueBoats(new int[]{3, 2, 2, 1}, 3)); // 3
        System.out.println(prob.numRescueBoats(new int[]{3, 5, 3, 4}, 5)); // 4
        System.out.println(prob.numRescueBoats(new int[]{3, 5, 3, 4, 2}, 5)); // 4
    }
}

@@ -170,32 +170,665 @@
     
-// TODO%0A        return 0
+int count = 0;%0A        boolean%5B%5D visited = new boolean%5Bpeople.length%5D;%0A        for (int i = 0; i %3C people.length; i++) %7B%0A            if (visited%5Bi%5D) %7B%0A                continue;%0A            %7D%0A            int l = limit - people%5Bi%5D;%0A            for (int j = i + 1; j %3C people.length; j++) %7B%0A                if (visited%5Bj%5D) %7B%0A                    continue;%0A                %7D%0A                if (l - people%5Bj%5D %3E= 0) %7B%0A                    l -= people%5Bj%5D;%0A                    visited%5Bj%5D = true;%0A                    if (l == 0) %7B%0A                        break;%0A                    %7D%0A                %7D%0A            %7D%0A            count++;%0A        %7D%0A        return count
 ;%0A  
@@ -921,16 +921,18 @@
 m881();%0A
+//
         
@@ -997,16 +997,18 @@
 ); // 1%0A
+//
         
@@ -1079,16 +1079,18 @@
 ); // 3%0A
+//
         
@@ -1157,24 +1157,26 @@
 , 5)); // 4%0A
+//
         Syst
@@ -1246,16 +1246,190 @@
 ); // 4%0A
+//        System.out.println(prob.numRescueBoats(new int%5B%5D%7B3, 5, 3, 2, 4%7D, 5)); // 4%0A        System.out.println(prob.numRescueBoats(new int%5B%5D%7B21, 40, 16, 24, 30%7D, 50)); // 3%0A
     %7D%0A%7D%0A

Update problem 881