Help me in solving WEPCH problem

My issue

I can’t understand what is wrong in this code, why is it failing test cases? Kindly help please anybody. Thank you so much!

My code

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

int main() {
    int T,H,X,Y1,Y2,K;
    cin>>T;
    while(T--){
        cin>>H>>X>>Y1>>Y2>>K;
        int timeX = ceil((float)H/X);
        int timeY = ceil((float)H/Y1);
        if(timeY>K){
            timeY = K + ceil((float)(H-Y1*K)/Y2);
        }
        cout<<min(timeX, timeY)<<endl;
    }
}

Problem Link: Weapon Choice Practice Coding Problem - CodeChef

@govind_dwivedi
plzz refer my c++ code

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

int main() {
	// your code goes here
    int t;
    cin>>t;
    while(t--)
    {
        long long int h,x,y1,y2,k;
        cin>>h>>x>>y1>>y2>>k;
        long long int p1=ceil(h*1.0/x*1.0);
        long long int p2=0;
        if(k*y1>=h)
        {
            p2=ceil(h*1.0/y1*1.0);
        }
        else
        {
            p2=k;
            h=h-(k*y1);
            p2+=ceil(h*1.0/y2*1.0);
        }
        cout<<min(p1,p2)<<endl;
    }
}
1 Like

Thanks, @dpcoder_007. I just changed from explicit conversion to implicit conversion of int to float and it got accepted. Although it is weird but I think there must be some issue over accuracy or maybe the testing method would have been designed in such a way that it is accepted only when converted implicitly by multiplying to 1.0.
If anybody here could give more definite answer on why my first code was rejected but second was selected, then that would be really helpful.
Thanks in advance!

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

int main() {
    int T,H,X,Y1,Y2,K;
    cin>>T;
    while(T--){
        cin>>H>>X>>Y1>>Y2>>K;
        int timeX = ceil((H*1.0)/X);
        int timeY = ceil((H*1.0)/Y1);
        if(timeY>K){
            timeY = K + ceil(((H-Y1*K)*1.0)/Y2);
        }
        cout<<min(timeX, timeY)<<endl;
    }
}