Branimirko is still a passionate player of the world-renowned game Pokémon Go. Recently,
he decided to organize a competition in catching Pokémon. It will be held in Ilica street in
Zagreb, and the main sponsor is his friend Slavko. The reward is, of course, candy!
Ilica is, as we all know, the longest street in Zagreb. There are N houses on the same side of
the street, and each house has a house number between 1 and N. The competition begins
at house number K.
Before the competition, Branimirko looked at the map and saw M Pokémon. Each Pokémon
is located at its (distinct) house number Ai
, is valued at Bi candy, and can be caught only in
the next Ti seconds, after which it disappears from the map and is impossible to catch.
Branimirko can visit one house number per second. Also, when he catches a Pokémon, that
Pokémon disappears from the map.
Since Branimirko really likes candy, he asked for your help.
Help him and determine the maximal amount of candy he can get!