logo AlgoBeat OnlineJudge
登录 注册

#104781. [BZOJ 4781] [Usaco2017 Open]Paired Up

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:传统 评测方式:无测试数据
上传者: 匿名

题目描述

Farmer John finds that his cows are each easier to milk when they have another cow nearby for moral support. He therefore wants to take his cows and partition them into pairs. Each pair of cows will then be ushered off to a separate stall in the barn for milking. The milking in each of these stalls will take place simultaneously.

To make matters a bit complicated, each of Farmer John's cows has a different milk output. If cows of milk outputs and are paired up, then it takes a total of units of time to milk them both.

Please help Farmer John determine the minimum possible amount of time the entire milking process will take to complete, assuming he pairs the cows up in the best possible way.

输入格式

The first line of input contains .
Each of the next lines contains two integers and , indicating that FJ has cows each with milk output . The sum of the 's is , the total number of cows.

输出格式

Print out the minimum amount of time it takes FJ's cows to be milked, assuming they are optimally paired up.

样例

样例输入 #1

3
1 8
2 5
1 2

样例输出 #1

10

样例解释

Here, if the cows with outputs are paired up, and those with outputs are paired up, the both stalls take units of time for milking. Since milking takes place simultaneously, the entire process would therefore complete after units of time. Any other pairing would be sub-optimal, resulting in a stall taking more than units of time to milk.

数据范围与提示

对于 的数据, 是偶数,

Silver