[Solved] Problem in Python code for LOC172 - "How many Pizzas"

Problem link (Contest) - https://www.codechef.com/LOCMAY17/problems/LOC172

I solved the above problem in C++ (C++14), but my Python (PYTH 3.4) solution is getting WA.

My Approach :-

  • Store the end-points of Y - Coordinates of the range each robot in an array - “Coord”.
  • Sort the array - “Coord”.
  • Generate the new end-points using coordinate compression, so that the new coordinates lie in the range [0, 2*N], where N = Number of robots.
  • Now, the max number of overlapping intervals is the required answer.

I’m unable to find the error in the Python code.

C++ (C++14) Code (AC) - https://www.codechef.com/viewsolution/13888744

Python (PYTH 3.4) Code (WA) - https://www.codechef.com/viewsolution/13888800

a = lower_bound(Coord, r[i][1]-r[i][2])
b = lower_bound(Coord, r[i][1]-r[i][2])

Pretty sure that will be

a = lower_bound(Coord, r[i][1]-r[i][2])
b = lower_bound(Coord, r[i][1]+r[i][2])

Also, this doesn’t affect the algorithm, but r=[0,0,0]*n actually makes a list of size 3n filled with zeroes, which I don’t think you intended.

2 Likes

Thanks @meooow, that was the problem. Maybe I just copied the above line and forgot to change the minus ‘-’ sign.

Yeah, that happens :stuck_out_tongue:

1 Like
//