forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2279.java
29 lines (27 loc) · 881 Bytes
/
_2279.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.fishercoder.solutions;
import java.util.Arrays;
public class _2279 {
public static class Solution1 {
public int maximumBags(int[] capacity, int[] rocks, int additionalRocks) {
int[] delta = new int[capacity.length];
int ans = 0;
for (int i = 0; i < capacity.length; i++) {
if (capacity[i] == rocks[i]) {
ans++;
} else {
delta[i] = capacity[i] - rocks[i];
}
}
Arrays.sort(delta);
for (int i = 0; i < capacity.length; i++) {
if (delta[i] != 0) {
if (additionalRocks >= delta[i]) {
ans++;
additionalRocks -= delta[i];
}
}
}
return ans;
}
}
}