logo AlgoBeat OnlineJudge
登录 注册

#217699. [PacNW 2025] Training, Round 4

内存限制:2048 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Ashley is training for another programming contest. Her coach Tom has prepared a list of problems that she must solve in order. Every problem has a positive integer implementation difficulty and thinking difficulty.

Ashley starts with some implementation skill and thinking skill. She can solve a problem if and only if both skills are at least the corresponding difficulties. After solving a problem, exactly one of her two skills increases by , and she chooses which one.

Find the minimum possible sum of Ashley's two initial skill levels that allows her to solve every problem in order.

输入格式

The first line contains an integer ().

Each of the next lines contains two integers and (), the implementation and thinking difficulties of one problem. Problems are given in the required order.

输出格式

Output the minimum possible sum of Ashley's initial implementation and thinking skills.

样例

样例输入 1

3
4 4
5 1
1 5

样例输出 1

8

样例输入 2

3
4 4
1 6
6 1

样例输出 2

10

样例输入 3

2
33 33
34 34

样例输出 3

67