Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool div(vector<int>& nums,int n,int maxOperations){
- if(nums.size()==1){
- return nums[0]/n<=maxOperations+1;
- }
- for(int i=0;i<nums.size();i++){
- if(maxOperations==0){
- if(nums[i]>n){
- return false;
- }else{
- return true;
- }
- }
- // cout<<maxOperations<<' ';
- if(nums[i]/n>maxOperations+1){
- cout<<"1:"<<maxOperations<<' ';
- return false;
- }else{
- maxOperations-=nums[i]/n-1;
- // if(nums[i]%(maxOperations+1)>n){
- // maxOperations--;
- // }
- cout<<"2:"<<maxOperations<<' ';
- if(maxOperations<0){
- return false;
- }
- }
- }
- return true;
- }
- int b_s(vector<int> & nums,int left,int right,int maxOperations){
- int mid=left+right;
- mid/=2;
- while(left<right){
- if(div(nums,mid,maxOperations)){
- return b_s(nums,left,mid,maxOperations);
- }else{
- return b_s(nums,mid+1,right,maxOperations);
- }
- }
- return mid;
- }
- int minimumSize(vector<int>& nums, int maxOperations) {
- sort(nums.begin(),nums.end());
- reverse(nums.begin(),nums.end());
- cout<<div(nums,6,maxOperations);
- return 0;
- return b_s(nums,1,nums.back(),maxOperations);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement