{"problem":{"name":"Candles","description":{"content":"There are $N$ candles on an infinite number line. The $i$\\-th candle is at the coordinate $X_i$. At time $0$, it has a length of $A_i$ and is lit. Each minute, the length of a lit candle decreases by ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc219_h"},"statements":[{"statement_type":"Markdown","content":"There are $N$ candles on an infinite number line. The $i$\\-th candle is at the coordinate $X_i$. At time $0$, it has a length of $A_i$ and is lit. Each minute, the length of a lit candle decreases by $1$. When the length becomes $0$, it burns out, and its length does not change after that. Additionally, the length of an unlit candle does not change.\nTakahashi is at the coordinate $0$ at time $0$. Each minute, he can move a distance of at most $1$. If there is a candle at his current coordinate, he can put out that candle. (If there are multiple candles there, he can put out all of them.) The time it takes to put out a candle is negligible.\nFind the maximum possible total length of the candles remaining at $10^{100}$ minutes after time $0$, achieved by Takahashi's optimal course of actions.\n\n## Constraints\n\n*   $1 \\leq N \\leq 300$\n*   $-10^9 \\leq X_i \\leq 10^9$\n*   $1 \\leq A_i \\leq 10^9$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$X_1$ $A_1$\n$X_2$ $A_2$\n$:$\n$X_N$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc219_h","tags":[],"sample_group":[["3\n-2 10\n3 10\n12 10","11\n\nThe third candle, which is at coordinate $12$, will burn out before Takahashi puts it out, regardless of Takahashi's behavior.  \nFor the other two candles, if he goes to coordinate $-2$ in two minutes to put out the first and then goes to coordinate $3$ in five minutes to put out the second, the lengths of those candles will not change after that. The lengths of those candles remaining are $10-2=8$ and $10-2-5=3$, for a total of $8+3=11$, which is the maximum that can be achieved. Thus, print $11$."],["5\n0 1000000000\n0 1000000000\n1 1000000000\n2 1000000000\n3 1000000000","4999999994\n\nNote that two or more candles may occupy the same coordinate and that the answer may not fit into a $32$\\-bit integer."]],"created_at":"2026-03-03 11:01:14"}}