Doubt in this question

I am solving this question from codeforces…
https://codeforces.com/problemset/problem/1424/G

Not able to come up with a proper logic…
Could you give some hint.
Thanks

hello @ashishnnnnn wait let me go through the question .

Hii… this is one other guy submission… Which has accepted…
But not able to understand the logic properly…

hey @ashishnnnnn have you seen the editorial ?

There is no editorial available for this question.

okay wait i will explain you the code which you have shared .

If possible… Please explain me the approch…

hey @ashishnnnnn lets now discuss from begining what you have understood in this code ?

@ashishnnnnn in this question it is given that there is book in which the persons birth and the death year is stored .
we have to find in which year there are the maximum number of people who are alive and how many people are there in total in that particular year .

Yes… We have to find that…
initally i though that for each age range we will increase a map value by 1… and then print the maximum value of age along with year…
But that approch is n*(d-b)… and this will give tle

which implementation you are talking about will give tle ?

the code which you have shared ,i dont think it will give tle .

Yaa… that will not give tle…
I am talking about my though …or my approch towards this question

@ashishnnnnn yes .
have you understood the code ? or are you facing any other problem ?

Not… really
Like it feels i am memorizing this approch… Not able to get the intuition behind this code…

@see you have birth year and death year and you have to calculate the number of people in a every year which are alive .
see we have taken one map in which we are taking two variables input for n times .
suppose the two variables are a and b .
a is the birth year and b is the death year .
so what we will do is in map we will increment for the birthyear at index ‘a’ and decrement at index ‘b’ this is because in the ath year one more person is born and so the total number of person have increased by 1 but if the person dies in the bth year so we have to decrement at this location because we have now one person less in the bth year so that is why we are incrementing at ath year and decrementing at bth year .
and then what will do is we will try to take sum of all the frequencies stored in the map and from that we will find the maximum people in particular year .
and in the aximum particular year we will store the number of people as well .

Hii…
Thanks now i got the intuition… You have explained it very intuitively.
Thanks

hey @ashishnnnnn if your doubt is cleared please mark this doubt as resolved and after that you can give rating there .
Happy Learning !!

Yaa sure :slight_smile: