Skip to content

Commit

Permalink
Create 1760_Minimum_Limit_of_Balls_in_a_Bag.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing-avil authored Dec 7, 2024
1 parent b11f8cb commit 4bd9266
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 1760_Minimum_Limit_of_Balls_in_a_Bag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ███████╗ █████╗ ███╗ ██╗ ██████╗ █████╗ ██████╗ ██████╗ ██╗ ██╗
// ██╔════╝ ██╔══██╗ ████╗ ██║ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██║ ██║
// ███████╗ ███████║ ██╔██╗ ██║ ██║ ██║ ███████║ ██████╔╝ ██████╔╝ ███████║
// ╚════██║ ██╔══██║ ██║╚██╗██║ ██║ ██║ ██╔══██║ ██╔═██╗ ██╔══██╗ ██╔══██║
// ███████║ ██║ ██║ ██║ ╚████║ ██████╔╝ ██║ ██║ ██║ ██╗ ██████╔╝ ██║ ██║
// ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
#pragma GCC optimize("Ofast", "inline", "ffast-math", "unroll-loops","no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native", "f16c")
auto init = []() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 'c';
}();
class Solution {
public:
int minimumSize(vector<int>& nums, int maxOperations) {
int s =1, e = *max_element(nums.begin(), nums.end());
while(s<e){
int mid = (s+e)>>1;
long long cnt = 0;
for (int x : nums) {
cnt += (x - 1) / mid;
}
if(cnt <= maxOperations){
e = mid;
}
else{
s = mid+1;
}
}
return s;
}
};

0 comments on commit 4bd9266

Please sign in to comment.