Advertisement
jibha

Untitled

Feb 8th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. class Solution {
  2. public:
  3.  
  4. bool div(vector<int>& nums,int n,int maxOperations){
  5.  
  6. if(nums.size()==1){
  7. return nums[0]/n<=maxOperations+1;
  8. }
  9.  
  10. for(int i=0;i<nums.size();i++){
  11.  
  12. if(maxOperations==0){
  13. if(nums[i]>n){
  14. return false;
  15. }else{
  16. return true;
  17. }
  18. }
  19. // cout<<maxOperations<<' ';
  20. if(nums[i]/n>maxOperations+1){
  21. cout<<"1:"<<maxOperations<<' ';
  22. return false;
  23. }else{
  24.  
  25. maxOperations-=nums[i]/n-1;
  26. // if(nums[i]%(maxOperations+1)>n){
  27. // maxOperations--;
  28. // }
  29. cout<<"2:"<<maxOperations<<' ';
  30. if(maxOperations<0){
  31. return false;
  32. }
  33. }
  34. }
  35.  
  36.  
  37. return true;
  38. }
  39.  
  40.  
  41. int b_s(vector<int> & nums,int left,int right,int maxOperations){
  42.  
  43. int mid=left+right;
  44. mid/=2;
  45.  
  46. while(left<right){
  47.  
  48. if(div(nums,mid,maxOperations)){
  49. return b_s(nums,left,mid,maxOperations);
  50. }else{
  51. return b_s(nums,mid+1,right,maxOperations);
  52. }
  53.  
  54. }
  55.  
  56. return mid;
  57. }
  58.  
  59. int minimumSize(vector<int>& nums, int maxOperations) {
  60.  
  61. sort(nums.begin(),nums.end());
  62. reverse(nums.begin(),nums.end());
  63.  
  64. cout<<div(nums,6,maxOperations);
  65.  
  66. return 0;
  67.  
  68. return b_s(nums,1,nums.back(),maxOperations);
  69.  
  70. }
  71. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement