Hello. I've tried to solve the problem using Python's heapq module, but that gave me 'Time limit exceeded' for the 2nd test case. I've checked the analysis and it claims that this approach should work for the 2nd test case. Am I missing something here? My code:

from heapq import heappop, heappush


def main():
    T = int(input())  # the number of test cases

    for case in range(1, T+1):
        N, K = map(int, input().split())

        h = [-N]

        for _ in range(K):
            chunk = -heappop(h)
            if chunk & 1:
                if chunk == 1:
                    min_s = max_s = 0
                else:
                    min_s = max_s = chunk >> 1
                    heappush(h, -min_s)
                    heappush(h, -max_s)
            else:
                max_s = chunk >> 1
                min_s = max_s - 1
                heappush(h, -min_s)
                heappush(h, -max_s)

        print('Case #{}: {} {}'.format(case, max_s, min_s))


main()





--
Regards,
  Eugene

--
You received this message because you are subscribed to the Google Groups "Google 
Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/f6b8ece9-0d14-5a39-d01f-d75d1acf9187%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to