Three Boxes | ThreeBox | Codechef Solution | Codechef October Challenge 2021 | TechTalkBot
Code:- THREEBOX
Name:- Three Boxes
Codechef October 2021 long challenge
By TECHTALKBOT
Chef has boxes of sizes , , and respectively. He puts the boxes in bags of size (). Find the minimum number of bags Chef needs so that he can put each box in a bag. A bag can contain more than one box if the sum of sizes of boxes in the bag does not exceed the size of the bag.
Chef has boxes of sizes , , and respectively. He puts the boxes in bags of size (). Find the minimum number of bags Chef needs so that he can put each box in a bag. A bag can contain more than one box if the sum of sizes of boxes in the bag does not exceed the size of the bag.
Input Format
- The first line contains denoting the number of test cases. Then the test cases follow.
- Each test case contains four integers , , , and on a single line denoting the sizes of the boxes and bags.
- The first line contains denoting the number of test cases. Then the test cases follow.
- Each test case contains four integers , , , and on a single line denoting the sizes of the boxes and bags.
Output Format
For each test case, output on a single line the minimum number of bags Chef needs.
For each test case, output on a single line the minimum number of bags Chef needs.
Constraints
Subtasks
Subtask 1 (100 points): Original constraints
Subtask 1 (100 points): Original constraints
Sample Input 1
3
2 3 5 10
1 2 3 5
3 3 4 4
3
2 3 5 10
1 2 3 5
3 3 4 4
Sample Output 1
1
2
3
1
2
3
Explanation
Test case : The sum of sizes of boxes is which is equal to the size of a bag. Hence Chef can put all three boxes in a single bag.
Test case : Chef can put boxes of size and in one bag and box of size in another bag.
Test case : Chef puts all the boxes in separate bags as there is no way to put more than one box in a single bag.
Test case : The sum of sizes of boxes is which is equal to the size of a bag. Hence Chef can put all three boxes in a single bag.
Test case : Chef can put boxes of size and in one bag and box of size in another bag.
Test case : Chef puts all the boxes in separate bags as there is no way to put more than one box in a single bag.
Solution:
- #include<iostream>using namespace std;int main(){ int t; cin>>t; while(t--) { int a,b,c,d,bag=0; cin>>a>>b>>c>>d; if(a+b+c<=d){ bag++ ; cout<< bag << endl ; } else if(c+b<=d){ bag = 2 ; cout<< bag << endl ; } else{ bag++ ; if(a+b<=d){ bag++ ; cout<< bag << endl ; } else{ bag+=2 ; cout<< bag << endl ; } } } }
- #include<iostream>using namespace std;int main(){int t;cin>>t;while(t--){int a,b,c,d,bag=0;cin>>a>>b>>c>>d;if(a+b+c<=d){bag++ ;cout<< bag << endl ;}else if(c+b<=d){bag = 2 ;cout<< bag << endl ;}else{bag++ ;if(a+b<=d){bag++ ;cout<< bag << endl ;}else{bag+=2 ;cout<< bag << endl ;}}}}
Conclusion:
- Keep ReadingThank You
If you are interested in Google Analytics Academy CertificationCheck out this-
- Keep ReadingThank YouIf you are interested in Google Analytics Academy CertificationCheck out this-
Tags:
Solutions
This comment has been removed by the author.
ReplyDelete