Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int distributionMultipleBags(int bags,int shirts){
- int shirtPerBag = shirts/bags;
- int equalShirtsTotal = shirtPerBag * (bags - 1);
- int inequalBag = shirts - equalShirtsTotal;
- int minDifference = abs(shirtPerBag - inequalBag);
- shirtPerBag++;
- equalShirtsTotal = shirtPerBag * (bags - 1);
- while(equalShirtsTotal < shirts){
- inequalBag = shirts - equalShirtsTotal;
- minDifference = min(minDifference,abs(shirtPerBag - inequalBag));
- shirtPerBag++;
- equalShirtsTotal = shirtPerBag * (bags - 1);
- }
- return minDifference;
- }
- int main(){
- int shirts = 107;
- int bags = 10;
- cout<<distributionMultipleBags(bags,shirts)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement