#P2808. Maximizing Dumpling Flavors

    ID: 16069 Type: Default 1000ms 256MiB

Maximizing Dumpling Flavors

Maximizing Dumpling Flavors

JOI has a delicious set meal consisting of NN xiaolongbao (soup dumplings) arranged in a line and numbered from 11 to NN. The distance between dumpling ii and dumpling jj is given by ij|i-j|. Initially, each dumpling has a flavor value of 00. JOI will eat the dumplings in a chosen order. When he eats dumpling ii, its hot soup spreads to all uneaten dumplings whose positions jj satisfy

[ i - D_i \le j \le i + D_i, ]

and each such dumpling has its flavor increased by AiA_i. That is, if dumpling ii is eaten, then for every dumpling jj that has not yet been eaten and satisfies

[ |i-j| \le D_i, ]

its flavor increases by AiA_i. 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 NN and for each dumpling the parameters AiA_i and DiD_i, 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 Format:
  • Output a single integer, the maximum total taste score.

inputFormat

The first line contains an integer NN (1N15)(1 \le N \le 15) representing the number of dumplings. Each of the following NN lines contains two space‐separated integers AiA_i and DiD_i, where AiA_i is the amount by which the flavor increases for dumplings within range when dumpling ii is eaten, and DiD_i 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