Skip to content

Commit 0579574

Browse files
Add Solution
1 parent 00594f0 commit 0579574

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Maximum Bags With Full Capacity of Rocks
2+
[Question](https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/description/)
3+
4+
# Solution:
5+
6+
```cpp
7+
class Solution {
8+
public:
9+
int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {
10+
11+
int count = 0;
12+
for(int i=0;i<capacity.size();i++) capacity[i] -= rocks[i];
13+
14+
sort(capacity.begin(), capacity.end());
15+
16+
for(int i=0;i<capacity.size() && additionalRocks>0;i++) {
17+
if(capacity[i] == 0) {
18+
count++;
19+
} else {
20+
int temp = additionalRocks - capacity[i];
21+
if(temp == 0) {
22+
count++;
23+
break;
24+
} else if(temp < 0) {
25+
break;
26+
} else {
27+
additionalRocks = temp;
28+
count++;
29+
}
30+
}
31+
}
32+
return count;
33+
}
34+
};
35+
```

0 commit comments

Comments
 (0)