Purchasing Presents

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 16M

Problem types

Fardin is planning to buy presents for all his teachers. However, he only has C dollars! Given N number of presents Fardin wants to buy, output how much money he will have left. If he is unable to buy all the presents, output Fardin's broke.

Input Specification

Line 1: N (1 \le N \le 500)

Line 2: C (0.00 \le C \le 250\,000.00)

The next N lines each contain the price of a present. All prices will be given to two decimal places.

Output Specification

If Fardin cannot buy all the presents, output the string Fardin's broke. Otherwise, output to 2 decimal places how much money Fardin has left.

Sample Input 1


Sample Output 1


Sample Input 2


Sample Output 2

Fardin's broke


  • -1
    LucaC  commented on May 14, 2020, 5:25 a.m.

    Hello, I can't seem to input an amount of money because it says this: ValueError: invalid literal for int() with base 10: '20.00'. I'm using python 3 so if anyone can help, it'll be much appreciated. Thank you!

    • 2
      ThePeeps191  commented on Aug. 1, 2021, 9:38 p.m.

      use float() instead of int()

    • -4
      hocianwade  commented on April 8, 2021, 9:39 a.m.

      try removing the decimal points maybe?

  • 1
    Pleedoh  commented on May 22, 2017, 7:28 p.m.

    Case 2 and 5, is 0 the wrong answer? Is it supposed to print something else, or is there something to do with rounding and he can't actually afford it?

    • 0
      DKLS2  commented on May 22, 2017, 9:37 p.m. edited

      You need to round to two decimal points for your answer to work(i.e. 0.00 not 0 or 0.0).

      • 0
        Pleedoh  commented on May 24, 2017, 5:09 p.m.

        ah, thanks

  • -1
    Kirito  commented on March 12, 2016, 4:26 p.m.

    In Turing, case 5 evaluates to an error margin of 2.664535e-15

  • -1
    Quality_of_Perfection  commented on March 12, 2016, 3:09 p.m.

    Test Case 5 while working in Java does not seem to be working.

    • -1
      Kirito  commented on March 12, 2016, 4:31 p.m. edited

      I think this has something to do with how floating points are subtracted.

      2 hints: 1) 1 cent = $0.01 2) Why are you subtracting?

      3rd hint: See my other comment.

  • 0
    SoundwaveSuperior  commented on Feb. 20, 2016, 4:19 p.m.

    Has the test data been fixed because this seems like a really simple problem but I keep getting one case incorrect (case 5).

    • 1
      awaykened  commented on Feb. 21, 2016, 12:14 a.m.

      the test data is fixed, doing this in C++ is just kind of a challenge due to double precision errors

      there are some workarounds, but i'll leave it to you to find them :P

  • 0
    bobhob314  commented on Dec. 14, 2015, 5:30 p.m.

    Hello, not sure if this is an error in observation but the test data appears to be incorrect. For test case 2 and 5, both of them have equal C and total gift cost but they do not have the same answer.

    • 0
      odaniel  commented on Dec. 14, 2015, 5:37 p.m.

      I have noticed this too.

    • 0
      awaykened  commented on Dec. 14, 2015, 5:37 p.m.

      You seem to be correct. One of the output files were incorrect due to python precision errors. Data will be fixed and submissions will be rejudged, sorry to everyone for the inconvenience.