Need help in the optimization

Pages: 12
But he hasn't posted here in a long time... ;)
Well, the more people who use this forum to cheat, the more disqualifications there will be, and the lower that success rate will be...
@MikeyBoy,
I thinks it's not that easy. I guess these cheaters are smart enough to use different user names and might slightly modify the code.
Absolutely nothing about the posts these people have been cluttering up the forums with lately, suggests that "smart" is an accurate descriptor...
> I prefer Rhett Butler's solution.
¿what's that?

> can you please explain the possible() function a little more
1
2
3
4
5
6
def possible(demand, cost, balloons, target):
   """try to satisfy the demand without exceeding target cost or running out of balloons"""
   for d, c in zip(demand, cost):
      balloons -= how_many(d, c, target)

   return balloons >= 0
let's just analyse one single day
for example, you want 6 balloons and each balloon may be changed by 3 candies
¿can you do it with a cost of at most 8? ¿how many balloons do you need to give for that? ¿do you have that many balloons?
then to solve for a list you simply repeat the question in each day

suppose that you cannot solve for 8, then you increase, say to 13, you can so you decrease to 10... and so on
there you do a binary search to get in time

there still remains what's the upper limit, but I guess you can figure out that, and if not just put something really big.
what is the corner case? any hint
Corner cases are usually the min and max values for the input - very often the code breaks at these inputs.
any idea on how to do the surchess problem
Last edited on
Topic archived. No new replies allowed.
Pages: 12