Codeforces 955A - Feed the cat Need help

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;
}
1 Like

@montycs plz add this line to your code after calculating min to eight

cout<<"min to eight "<<extraTime<<endl;

You will be able to see your error. And then comment out this line before submitting.

You can see for this case you will get negative time. Which should not happen when you are after 8 just go and buy bread at 80% discount. No need to calculate two values and find minimum.

Hope this help. And plz reply whether go AC or still issue persist.

2 Likes

Thanks brother… Can’t believe I missed that test case… Thanks anyway

1 Like

@montycs Welcome. Happy Coding :slight_smile: