CHEFBOTTLE - Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Abhishek Aman
Tester: Aryan Choudhary, Abhinav sharma
Editorialist: Prakhar Kochar

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Chef has N empty bottles where each bottle has a capacity of X litres.
There is a water tank in Chefland having K 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.

EXPLANATION:

We are given N empty bottles. Capacity of each bottle is X litres. Thus, with K litres of water Chef can fill exactly \lfloor \frac{K}{X} \rfloor bottles completely. Following cases are possible:

  • \lfloor \frac{K}{X} \rfloor \geq N : This means we can fill all the N bottles completely.

  • \lfloor \frac{K}{X} \rfloor \lt N : This means we can only fill \lfloor \frac{K}{X} \rfloor bottles completely.

Here, \lfloor N \rfloor is floor(N) which represents the largest integer less than or equal to N.

Examples
  • N = 4, X = 4, K = 15;
    \lfloor \frac{15}{4} \rfloor = 3. Since 3 \lt 4, Chef can fill only 3 bottles completely.

  • N = 4, X = 4, K = 20;
    \lfloor \frac{20}{4} \rfloor = 5. Since 5 \gt 4, Chef can fill all the 4 bottles completely.

TIME COMPLEXITY:

O(1) for each test case.

SOLUTION:

Setter's Solution
#include <bits/stdc++.h>
using namespace std;

signed main(){
    // freopen("CHEFBOTTLE_3.in","r",stdin);
    // freopen("CHEFBOTTLE_3(Slow Check).out","w",stdout);
    int t;cin>>t;
    while(t--){
    	int N,X,K;cin>>N>>X>>K;
        int ans=0;
        while(N>0){
            K=K-X;
            if(K<=0) break;
            ans++;N--;
        }
    	cout<<ans<<"\n";
    }
}
Tester's Solution
#include <bits/stdc++.h>
using namespace std;
 
 
/*
------------------------Input Checker----------------------------------
*/
 
long long readInt(long long l,long long r,char endd){
    long long x=0;
    int cnt=0;
    int fi=-1;
    bool is_neg=false;
    while(true){
        char g=getchar();
        if(g=='-'){
            assert(fi==-1);
            is_neg=true;
            continue;
        }
        if('0'<=g && g<='9'){
            x*=10;
            x+=g-'0';
            if(cnt==0){
                fi=g-'0';
            }
            cnt++;
            assert(fi!=0 || cnt==1);
            assert(fi!=0 || is_neg==false);
 
            assert(!(cnt>19 || ( cnt==19 && fi>1) ));
        } else if(g==endd){
            if(is_neg){
                x= -x;
            }
 
            if(!(l <= x && x <= r))
            {
                cerr << l << ' ' << r << ' ' << x << '\n';
                assert(1 == 0);
            }
 
            return x;
        } else {
            assert(false);
        }
    }
}
string readString(int l,int r,char endd){
    string ret="";
    int cnt=0;
    while(true){
        char g=getchar();
        assert(g!=-1);
        if(g==endd){
            break;
        }
        cnt++;
        ret+=g;
    }
    assert(l<=cnt && cnt<=r);
    return ret;
}
long long readIntSp(long long l,long long r){
    return readInt(l,r,' ');
}
long long readIntLn(long long l,long long r){
    return readInt(l,r,'\n');
}
string readStringLn(int l,int r){
    return readString(l,r,'\n');
}
string readStringSp(int l,int r){
    return readString(l,r,' ');
}
 
 
/*
------------------------Main code starts here----------------------------------
*/
 
const int MAX_T = 1e5;
const int MAX_N = 1e5;
const int MAX_SUM_LEN = 1e5;
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define mp make_pair
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
int sum_n = 0, sum_m = 0;
int max_n = 0, max_m = 0;
int yess = 0;
int nos = 0;
int total_ops = 0;
ll mod = 1000000007;


void solve()
{   

    int n = readIntSp(1,1e5);
    int x = readIntSp(1,1e5);
    int k = readIntLn(0,1e5);

    cout<<min(k/x,n)<<'\n';


}
 
signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    fast;
    
    int t = 1;
    
    t = readIntLn(1,100);
    
    for(int i=1;i<=t;i++)
    {    
       solve();
    }
   
    assert(getchar() == -1);
   // assert(sum_n<=2e3);
 
    cerr<<"SUCCESS\n";
    cerr<<"Tests : " << t << '\n';
    cerr<<"Sum of lengths : " << sum_n <<'\n';
    cerr<<"Maximum length : " << max_n <<'\n';
    // cerr<<"Total operations : " << total_ops << '\n';
    //cerr<<"Answered yes : " << yess << '\n';
    //cerr<<"Answered no : " << nos << '\n';
}
Editorialist's Solution
#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define inf INT_MAX
#define mod 998244353

void f() {
    int n, x, k;
    cin >> n >> x >> k;
    int ans = min(n, k / x);
    cout << ans << "\n";
}

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while (t--) f();
}
5 Likes