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
#include <iostream>
using namespace std;
int main()
{
int a, b, c, d, t;
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--;
}
}