#P2808. Maximizing Dumpling Flavors
Maximizing Dumpling Flavors
Maximizing Dumpling Flavors
JOI has a delicious set meal consisting of xiaolongbao (soup dumplings) arranged in a line and numbered from to . The distance between dumpling and dumpling is given by . Initially, each dumpling has a flavor value of . JOI will eat the dumplings in a chosen order. When he eats dumpling , its hot soup spreads to all uneaten dumplings whose positions satisfy
[ i - D_i \le j \le i + D_i, ]
and each such dumpling has its flavor increased by . That is, if dumpling is eaten, then for every dumpling that has not yet been eaten and satisfies
[ |i-j| \le D_i, ]
its flavor increases by . When a dumpling is eaten, its current flavor is added to JOI’s total taste score. JOI can decide the eating order to maximize the total taste score.
Given the number of dumplings and for each dumpling the parameters and , find the maximum total taste score that JOI can achieve by choosing an optimal eating order.
Input Format:
- The first line contains one integer $N$.
- The next $N$ lines each contain two integers $A_i$ and $D_i$ for dumpling $i$.
- Output a single integer, the maximum total taste score.
inputFormat
The first line contains an integer representing the number of dumplings. Each of the following lines contains two space‐separated integers and , where is the amount by which the flavor increases for dumplings within range when dumpling is eaten, and is the spreading range.
outputFormat
Output one integer, the maximum total taste score JOI can obtain by choosing an optimal order to eat the dumplings.
sample
3
5 1
-3 1
2 1
7