- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
Jeff is very indecisive. Whenever an opportunity arises, he rarely decides to pursue it. Each opportunity in Jeff’s life has two characteristics:
: the amount of happiness Jeff would gain if he chooses to take this opportunity.
: the amount of energy it would cost Jeff to take this opportunity.
Jeff has a limited amount of energy, .
Over moments in Jeff's life, opportunities either appear or disappear:
- In the i-th moment, an opportunity with values (happiness) and (energy cost) either becomes available or, if it was already available, disappears.
Now, at the end of his life, Jeff is filled with regrets. For each moment , he wonders what the maximum happiness he could have achieved would have been if he had chosen to take some of the available opportunities, using no more than his available energy .
Since Jeff doesn’t have the time to solve this problem himself, he’s asking for your help.
input
the first line contains two integers and , the number of moments in Jeff's life and the amount of energy Jeff has.
for the next lines, the i-th line contains two integers each and the amount of happiness and the energy cost of the opportunity.
if Jeff previously had the opportunity with the same values the opportunity is no longer available otherwise the opportunity becomes available.
output
output should contain numbers the i-th number should be the maximum amount of happiness Jeff could've achieved if he had chosen to take some of the available opportunities at the i-th moment such that the amount of energy he loses is at most .
example
sample input 1
sample output 1
- in moment 1 available opportunities are Jeff can take opportunity and gain happiness
- in moment 2 available opportunities are Jeff can take opportunities and gain happiness
- in moment 3 opportunity disappears so opportunities are Jeff can take opportunity and gain happiness
- in moment 4 available opportunities are Jeff can take opportunity and gain happiness, he can't take both opportunities since his available energy is equal to but taking both opportunities would require energy of at least
ارسال پاسخ برای این سؤال