#K84937. Minimum Completion Time

    ID: 36530 Type: Default 1000ms 256MiB

Minimum Completion Time

Minimum Completion Time

You are given a sequence of tasks. Each task is represented by two integers: the duration of the task and the minimum gap required after completing that task.

You must perform the tasks sequentially. The total time to complete all tasks is computed by summing the duration and the gap for each task, but note that the gap after the final task is not needed.

The formula for the total time T when there are n tasks is given by:

$$ T = \sum_{i=1}^{n} (d_i + g_i) - g_n, \quad \text{if } n > 0, \quad \text{and } T = 0 \text{ if } n = 0. $$

Here, \(d_i\) represents the duration of the \(i^{th}\) task and \(g_i\) represents the minimum gap required after the \(i^{th}\) task.

inputFormat

The first line of input contains an integer n representing the number of tasks.

Each of the following n lines contains two space-separated integers d and g where:

  • d is the duration of the task, and
  • g is the minimum gap required after the task.

If n = 0, then there are no tasks.

outputFormat

Output a single integer representing the minimum total time required to complete all the tasks.

## sample
1
5 2
5