Advertisement
ridwan100

T-shirts-bag problem

Jan 29th, 2024 (edited)
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int distributionMultipleBags(int bags,int shirts){
  5.    
  6.     int shirtPerBag = shirts/bags;
  7.     int equalShirtsTotal = shirtPerBag * (bags - 1);
  8.     int inequalBag = shirts - equalShirtsTotal;
  9.     int minDifference = abs(shirtPerBag - inequalBag);
  10.     shirtPerBag++;
  11.     equalShirtsTotal = shirtPerBag * (bags - 1);
  12.     while(equalShirtsTotal < shirts){
  13.         inequalBag = shirts - equalShirtsTotal;
  14.         minDifference = min(minDifference,abs(shirtPerBag - inequalBag));
  15.         shirtPerBag++;
  16.         equalShirtsTotal = shirtPerBag * (bags - 1);
  17.     }
  18.    return minDifference;
  19. }
  20.  
  21.  
  22.  
  23. int main(){
  24.     int shirts = 107;
  25.     int bags = 10;
  26.    
  27.    
  28.     cout<<distributionMultipleBags(bags,shirts)<<endl;
  29.  
  30.    
  31.  
  32.  
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement