I am trying to solve Feed The Cat. But My implementation is failing 8th test case which is:
20 55
100000 100 100 100
Can anyone help in finding mistake in my implementation.
Here is my code:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
double calculateMinutesToEight(double h, double m)
{
int m1,m2;
m1 = 60 - m;
m2 = (20 - (h+1))*60;
return m1 + m2;
}
double beforeEight(double reqH, double c)
{
double res = reqH * c;
return res;
}
double afterEight(double reqH, double c)
{
double discount,ans;
discount = (reqH * c) * 0.2;
ans = (reqH * c) - discount;
return ans;
}
int main() {
// your code goes here
double hh,mm,h,d,c,n;
cin>>hh>>mm>>h>>d>>c>>n;
double requiriedBuns1 = ceil(h/n);
double result1 = beforeEight(requiriedBuns1,c);
double result2,extraTime,requiriedBuns2;
cout<<setprecision(10);
if(hh < 20)
{
extraTime = calculateMinutesToEight(hh,mm);
extraTime = extraTime * d;
requiriedBuns2 = ceil((h + extraTime)/n);
result2 = afterEight(requiriedBuns2,c);
}
else
{
requiriedBuns2 = ceil(h/n);
result2 = afterEight(requiriedBuns2,c);
}
cout<<min(result1, result2);
return 0;
}