An Unbroken Heart 1
Time limit1.5sMemory limit1024 MB
Given N dragons with start heights H[i] and daily growth D[i], find for each k the maximum total cut length when at most one arrow is shot per day from day 1 to k.
Problem
"N = 10000 is fine. What matters is a heart that does not break"
Your farm has dragons growing on it. Each dragon has a distinct number from to . Call today day 1. On day 1, the height of dragon is . Every time the day changes, the height of every dragon increases by .
Outside the farm, a thief is trying to steal your dragons with a sharp magic arrow. The thief can shoot at most one magic arrow per day, and a shot arrow hits exactly the dragon the thief aims for. When the arrow hits dragon , its height becomes 0, and the thief gets a piece of the dragon equal to the cut length (that is, the height the dragon had before it was hit). The thief may choose not to shoot, and may hit a dragon that was already hit earlier.
The dragons may be cut by the magic arrows, but their hearts do not break. Even if dragon has height 0, its height increases by again when the next day comes.
For every , assume the thief can shoot at most one arrow per day from day 1 to day . Find the maximum possible total length of dragon pieces the thief can obtain.
Input
The first line contains the number of dragons . ()
The next lines each contain two integers and . (, )
Output
Print lines. On line , print the answer for as a single integer.