#P7619. Mirko's Pizza Scheduling
Mirko's Pizza Scheduling
Mirko's Pizza Scheduling
Mirko's Pizza Shop is the best in town. Every resident enjoys his pizza for lunch. Although the delivery is extremely fast (nearly instantaneous), Mirko only has a single small oven that can bake one pizza at a time.
There are \( N \) residents numbered from 1 to \( N \). The i-th resident plans to have lunch at time \( L_i \) and his pizza requires \( T_i \) time units to bake.
If a resident receives his pizza \( K \) time units before \( L_i \), Mirko earns \( K \) dollars in tip. Conversely, if the pizza is delivered \( K \) time units after \( L_i \), Mirko must pay the resident \( K \) dollars. Delivering the pizza exactly on time results in neither a tip nor a penalty.
Help Mirko arrange the baking order for the day so that his total tip is maximized.
Note:
- The day starts at time 0 and is infinitely long.
- Residents may change their \( T_i \) and \( L_i \) over time.
inputFormat
The first line contains a single integer \( N \), the number of residents.
Each of the following \( N \) lines contains two integers \( T_i \) and \( L_i \), which represent the baking time and planned lunch time of the i-th resident respectively.
outputFormat
Output a single integer, the maximum total tip Mirko can obtain by optimally scheduling the baking order.
sample
3
6 10
8 15
5 12
2
</p>