1683:评测队列

文件提交:无需freopen 内存限制:128 MB 时间限制:1.000 S
评测方式:普通裁判 命题人:
提交:3 解决:2

题目描述

在一次算法比赛中,有 lns="http://www.w3.org/1998/Math/MathML"> 个程序提交到了竞赛平台上,测试每个程序需要两步:先编译,然后运行。

竞赛平台有两台服务器,一台只负责编译,另一台只负责运行,编译第 lns="http://www.w3.org/1998/Math/MathML"> 个程序的时间为 lns="http://www.w3.org/1998/Math/MathML">,运行第 lns="http://www.w3.org/1998/Math/MathML"> 个程序的时间为 lns="http://www.w3.org/1998/Math/MathML">。服务器必须按照提交顺序来处理任务,也就是说一定要先处理第一个程序,最后处理第 lns="http://www.w3.org/1998/Math/MathML"> 个程序。每台服务器在同一时刻只能处理一个任务。

请问平台需要多少时间才能测试完所有的程序?

输入

第一行:单个正整数 lns="http://www.w3.org/1998/Math/MathML">
第二行到第 lns="http://www.w3.org/1998/Math/MathML">+1 行:在第 lns="http://www.w3.org/1998/Math/MathML">+1 行,有两个整数 lns="http://www.w3.org/1998/Math/MathML"> 与 lns="http://www.w3.org/1998/Math/MathML">

lns="http://www.w3.org/1998/Math/MathML">1,10000

输出

单个整数:表示按照次序测试完所有程序的时间。

样例输入-1 复制

3
10 5
20 30
5 50

样例输出-1 复制

110