IPCTRAIN - Getting WA for higher data sets.

I tried many times this question but getting WA for higher test cases.
Since i did it with by two ways.

(1) Firstly i create a priority queue using STL(which is max heap by default) and then start loop for days 1 to D, and at the beginning of each i’th day, I put all the members who are coming on i’th day into queue and if queue is empty(in case of no trainers are available for those days) then do nothing. but if queue is not empty then then pop from queue and decrease its demand by 1 and if demand is still not zero then push it again into queue. and at last(after camp gets completed) all the elements that left in queue will give the answer
I tried it many times but getting AC only for small data sets. You can check my solution here

(2) After getting too many WA i did it using heap(std stl heap) with same approach as above.
But only time running time gets reduced, as still getting WA for higher data sets. You can see my second solution here.

Now Please tell me what’s wrong in my code…
Thanks in advance.

1 Like

Its overflow in your first solution.

If lectures sadness is 10^5 and he stays for 10^5 days, then the resulting product is 10^10 which is out of int’s range.

I just converted your PAIR and other variables to long long int and that did the trick.

https://www.codechef.com/submit/complete/14595361

2 Likes

Ohhh… Why my brain didn’t catch this at that time. Such a silly mistake i did.
Thank you @vijju123

3 Likes

Getting tle for the larger data sets. Can anyone help me out on how to make it more efficient.
Here’s my solution https://www.codechef.com/viewsolution/14582375

Did you have a look at the editorial?

Yes I did. But I didn’t very well understand the heap concept. But I think the rest of the logic is same.

Hello @shuvro97
I seen your code. but didn’t understand what you did at a glance. So it’s my advise to you please specify what’s approach you applied to design your solution. A explain in short what actually you did.
Because nobody has time to see your code and then find what approach you applied and then check where you did the mistake.
So please always put your approach in short with question…
I am always here for your help.

1 Like

Also, if you can ask a question, as it as a question, and not in form of “answer” inside a question. If you ask it as a question, at least it will stay on front page and get views. It slipped my mind that i had to take a look at your code, and there was no way to remind myself of it except seeing this question (which i most probably wont as its answered already)