You are not logged in. Please login at www.codechef.com to post your questions!

×

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

asked 27 Mar '18, 13:55

montycs's gravatar image

0★montycs
1057
accept rate: 0%

edited 27 Mar '18, 17:39


@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.

link

answered 27 Mar '18, 16:21

aryanc403's gravatar image

6★aryanc403
2.5k1516
accept rate: 10%

edited 27 Mar '18, 16:23

1

Thanks brother.. Can't believe I missed that test case.. Thanks anyway

(27 Mar '18, 17:40) montycs0★

@montycs Welcome. Happy Coding :)

(27 Mar '18, 21:31) aryanc4036★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,718
×825
×672

question asked: 27 Mar '18, 13:55

question was seen: 589 times

last updated: 27 Mar '18, 21:31