SP14893 GOODG - Good Inflation
Description
The competition is drawing to a close, and The Team could really use another balloon to help them come out on top...good thing they're no chumps, and thought of this in advance! Before the contest started, they instructed an accomplice to go to the local balloon shop, buy an extra balloon, and deliver it to them at the conclusion of the event. It is true that their balloons then won't match up with the scoreboard's record of which problems they've solved - but, in the end, it's the balloons that count! In fact, The Team knows that, the larger their extra balloon, the more their opponents (and the judges) will be intimidated. They're not the best ACM-ICPC team in the world for nothing!
However, this balloon shop is rather strange. The accomplice is given an empty balloon (a balloon with size 0), and told that he can tie it closed and keep it after exactly $ N $ ( $ 1 \leq N \leq 10^6 $ ) minutes. In the meantime, during each minute, an inflation offer is available. If offer $ i $ is taken, then, at the start of the $ i $ th minute, the balloon's size will be increased by $ a_i $ ( $ 0 \leq a_i \leq 10^6 $ ). However, since the balloon cannot be closed until the end, its air will leak out at a constant rate, which depends on the gas that was used - in particular, its size will immediately start to decrease at a rate of $ d_i $ ( $ 0 \leq d_i \leq 10^6 $ ) per minute, until either another offer is taken, or the balloon deflates completely (its size can never become negative, of course).
The Team will not be happy if they don't receive the largest balloon possible. Unfortunately, their accomplice happens to be...you. Can you figure out the maximal size that the balloon can have at the start of minute $ N+1 $ , before it's too late?
Input Format
First line: 1 integer, $ N $
Next $ N $ lines: 2 integers, $ a_i $ and $ d_i $ , for $ i=1..N $
Output Format
1 integer, the maximal size which the balloon can have at the start of minute $ N+1 $ .