Comments

There are a few smart observations that could help you pass it:

  • We are interested only in the sum so maintaining just the sum of let's say 1st p elements would help.
  • We can limit the search to the maximum size of students in a particular group

Also, I have observed iterating through numbers (for i in range(n)) is generally faster than iterating through the keys (for i in dict). Also you could try with fast I/O sometimes that solves TLE.

Meme
On Pranava23Python 3 vs PyPy 3, 6 years ago
0

Thank you:) I now understand the problem

On Pranava23Python 3 vs PyPy 3, 6 years ago
0

I used a simple iteration instead of the pop operation and the solution passed in both PyPy3 and Python3 but still, it was a bit faster in Python3 I don't know the reason behind the same, is there any reason for the same? Thank you:)

PyPy3

Python3

On Pranava23Python 3 vs PyPy 3, 6 years ago
0

Auto comment: topic has been updated by Pranava23 (previous revision, new revision, compare).