Algorithm


 problem Link :  https://www.codechef.com/problems/CHEFBOTTLE 

Problem

Chef has  empty bottles where each bottle has a capacity of  litres.
There is a water tank in Chefland having  litres of water. Chef wants to fill the empty bottles using the water in the tank.

Assuming that Chef does not spill any water while filling the bottles, find out the maximum number of bottles Chef can fill completely.

Input Format

  • First line will contain , number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, three integers �,�, and .

Output Format

For each test case, output in a single line answer, the maximum number of bottles Chef can fill completely.

Constraints

  • 1≤�≤100
  • 1≤�,�≤105
  • 0≤�≤105

Sample 1:

Input
 
Output
 
3
5 2 8
10 5 4
3 1 4
4
0
3

Explanation:

Test Case 1: The amount of water in the tank is 8 litres. The capacity of each bottle is 2 litres. Hence, 4 water bottles can be filled completely.

Test Case 2: The amount of water in the tank is 4 litres. The capacity of each bottle is 5 litres. Hence, no water bottle can be filled completely.

Test Case 3: The amount of water in the tank is 4 litres. The capacity of each bottle is 1 litre. Chef has 3 bottles available. He can fill all these bottles completely using 3 litres of water.

 

Code Examples

#1 Code Example with C Programming

Code - C Programming

 #include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define ul          unsigned long long
#define pb          push_back
#define ss          second
#define ff          first
#define fr(n)       for(int i=0; i < n; i++)
#define fro(n)      for(int i=1; i < n; i++)
#define frj(n)      for(int j=0; j < n; j++)
#define frr(n)      for(int i=n; i>=0; i--)
#define nl          '\n'
#define yes         cout<<"YES"<<nl
#define no          cout<<"NO"<<nl
#define all(x)      x.begin(), x.end()
#define dbg(x)    cerr << #x <<" "<< x << endl;
#define fast_io  (ios_base:: sync_with_stdio(false),cin.tie(NULL));

#define PI          3.141592653589793238
#define INF         LONG_LONG_MAX
#define MOD         1e9+7

ll fact(ll n){ if(n==0) return 1; ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res;}
ll nPr(ll n, ll r) { return fact(n) / fact(n - r); }
ll nCr(ll n, ll r) { return fact(n) / (fact(r) * fact(n - r)); }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b);}
ll mypow(ll a, ll b){ ll ans = 1; while(b){ if (b&1) ans = (ans*a) ; b /= 2; a = (a*a); } return ans; }
bool isPrime(ll n) { if(n  < = 1) return false; for(ll i = 2; i  < = sqrt(n); i++) if(n % i == 0) return false; return true;}

//////////////////////////////////Code Start/////////////////////////////////////

void solve(>
{
    int n,x,k;
    cin>>n>>x>>k;
    int b=k/x;
    if(b>=n)
        cout<<n<<nl;
    else
        cout<<b<<nl;
}
 
int main()
{
    fast_io;
    int TC = 1;
    cin >> TC;
    while (TC--) solve();
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 2 8
10 5 4
3 1 4

Output

x
+
cmd
4
0
3
Advertisements

Demonstration


CodeChef solution CHEFBOTTLE  =- Chef and Water Bottles Codechef solution in C,C++

Previous
CodeChef solution TRICOIN - Coins and Triangle Codechef solution in C,C++