304 North Cardinal St.
Dorchester Center, MA 02124

# The Mango Truck CodeChef Solution

## Problem – The Mango Truck CodeChef Solution

You are given that a mango weighs X kilograms and a truck weighs Y kilograms. You want to cross a bridge that can withstand a weight of Z kilograms.

Find the maximum number of mangoes you can load in the truck so that you can cross the bridge safely.

### Input Format

• First line will contain T, the number of test cases. Then the test cases follow.
• Each test case consists of a single line of input, three integers X,Y,Z – the weight of mango, the weight of truck and the weight the bridge can withstand respectively.

### Output Format

For each test case, output in a single line the maximum number of mangoes that you can load in the truck.

• 1≤T≤1000
• 1≤XYZ≤100

### Sample 1:

Input: 4
2 5 11
4 10 20
1 1 1
6 40 90
Output: 3
2
0
8

### Explanation:

Test case 1: You can load 3 mangoes at maximum. The total weight is 3\times 3×2+5=11≤11. Thus, the truck can safely cross the bridge with 3 mangoes. If you load 4 mangoes, the total weight is 4×2+5=13>11.

Test case 2: You can load 2 mangoes at maximum. The total weight is 2×4+10=18≤20. Thus, the truck can safely cross the bridge with 2 mangoes.

Test case 3: You can load 0 mangoes at maximum. The total weight is 0×1+1=1≤1. Thus, the truck can safely cross the bridge only if there are 0 mangoes.

Test case 4: You can load 8 mangoes at maximum. The total weight is 6×8+40=88≤90. Thus, the truck can safely cross the bridge with 8 mangoes.

### The Mango Truck CodeChef Solution in Java

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

class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scn= new Scanner(System.in);    //System.in is a standard input stream
int T= scn.nextInt();

for(int i=0; i<T; i++){
int X= scn.nextInt();
int Y= scn.nextInt();
int Z= scn.nextInt();

System.out.println((Z-Y)/X);
}
}
}


### The Mango Truck CodeChef Solution in Pyth 3

T = int(input())
for i in range(T):
X,Y,Z=map(int,input().split())
A = (Z-Y)//X
print(A)

### The Mango Truck CodeChef Solution in C++17

#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
int t;
cin>>t;
while(t--)
{
int x,y,z;
cin>>x>>y>>z;
z-=y;
if(z<0)
z=0;
z/=x;
cout<<z<<endl;
}
}
##### The Mango Truck CodeChef Solution Review:

In our experience, we suggest you solve this The Mango Truck CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the The Mango Truck CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this The Mango Truck CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions