TLE in IPCTRAIN

Please give me hints to optimize this solution to fit in the time limit for IPCTRAIN subtask 2.

Edit: I have now documented my code so that you might be able to understand what i have tried to do. :slight_smile:
Here is the link

Sorry, But It will be very hard to read someone’s code without any comment. Please provide some explanation around your answer and what you did in your code if you really want help from community… :slight_smile:

BTW, Why there are two for loops their, I think one for loop should be enough. May be that is reason why you are getting TLE, not sure though.

In simple words if I say, You iterate over days and if some teacher comes on ith day then just make priority queue according to sadness and put that teacher in that. And choose teacher with highest sadness on that day from same priority queue. Remember to remove teacher from priority queue if number of lectures he has to give is completed. Finally after n days just take sum of what is remaining in priority queue. Basically I am just trying to choose a teacher with highest sadness on ith day(among who have come till now), You can say it a Greedy approach.

I hope this will help.

1 Like

Hello… thanks for helping. I have now commented my code. By the way I understood the editorial. I just wanted to know the ways to optimize my code to fit in the time limit. :slight_smile: Hope that now you would be able to read my code.
And btw i also think that its the double loop that is causing problem.