# Three Boxes | CodeChef Solution

Hello coders, today we are going to solve Three Boxes CodeChef Solution whose Problem Code is THREEBOX.

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.

## Input Format

• The first line contains T denoting the number of test cases. Then the test cases follow.
• Each test case contains four integers A, B, C, and D 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.

## Constraints

• 1 ≤ T ≤ 100
• 1 ≤ A ≤ B ≤ C ≤ D ≤ 100

Subtask 1 (100 points): Original constraints

Sample Input 1

``````3
2 3 5 10
1 2 3 5
3 3 4 4
``````

Sample Output 1

``````1
2
3
``````

Explanation

Test case 1: The sum of sizes of boxes is 2+3+5=10 which is equal to the size of a bag. Hence Chef can put all three boxes in a single bag.

Test case 2: Chef can put boxes of size 1 and 3 in one bag and box of size 2 in another bag.

Test case 3: Chef puts all the boxes in separate bags as there is no way to put more than one box in a single bag.

## Solution – Three Boxes | CodeChef Solution

### C++

```#include <iostream>
using namespace std;

int main() {
int test;
cin >> test;

while (test--){
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a + b + c <= d){
cout << 1 << endl;
}
else if (a + b <= d){
cout << 2 << endl;
}
else{
cout << 3 << endl;
}
}
return 0;
}
```

### Python

```# cook your dish here
T = int(input())
while (T > 0):
a, b, c, d = map(int, input().split())

if (a + b + c <= d):
print(1)
elif (a + b <= d):
print(2)
else:
print(3)
T = T - 1```

### Java

```/* package codechef; // don't place package name! */

import java.util.Scanner;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner input = new Scanner(System.in);
int test = input.nextInt();
while (test > 0){

int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int d = input.nextInt();

if (a + b + c <= d){
System.out.println(1);
}
else if (a + b <= d){
System.out.println(2);
}
else{
System.out.println(3);
}
test = test - 1;
}
}
}
```

Disclaimer: The above Problem (Three Boxes) is generated by CodeChef but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.