Chef has 3 boxes of sizes A, B, and C respectively. He puts the boxes in bags of size D (A≤B≤C≤D). 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 3 boxes of sizes A, B, and C respectively. He puts the boxes in bags of size D (A≤B≤C≤D). 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






OURSHOPKEEPER










#include <iostream>
using namespace std;
int main()
{
    int abcdt;
    cin >> t;
    while (t>0)
    {
        int count = 1;
        cin >> a >> b >> c >> d;
        if (a + b + c <= d)
        {
            cout << count<<endl;
        }
        else if (a + b + c >= d)
        {
            if (a + b <= d || a + c <= d || b + c <= d)
            {
                count++;
                cout << count<<endl;
            }
            else if (a + b > d && b + c > d && c + a > d)
            {
                ++count;
                count++;
                cout << count<<endl;
            }
        }
        t--;
    }
}




    


Click on the above button to download the code.



Post a Comment

If you have furthur QUERIES please let us know

Previous Post Next Post