import java.util.Arrays;
class Solution {
public int numRescueBoats(int[] people, int limit) {
int len = people.length;
int ans = 0;
Arrays.sort(people);
int l = 0;
int r = len - 1;
while (l <= r) {
if (people[l] + people[r] <= limit) {
l++;
}
r--;
ans++;
}
return ans;
}
}