#P3669. [USACO17OPEN] Paired Up S
[USACO17OPEN] Paired Up S
题目描述
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 (, even) 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.
题目大意
题目描述
Farmer John 发现,当他的奶牛附近有另一头奶牛提供精神支持时,每头奶牛挤奶会更容易。因此,他希望将他的 头奶牛(, 为偶数)分成 对。每对奶牛将被引导到谷仓中一个单独的隔间进行挤奶。这些 个隔间中的挤奶过程将同时进行。
为了增加一些复杂性,Farmer John 的每头奶牛都有不同的产奶量。如果产奶量分别为 和 的两头奶牛被配对,那么挤完它们总共需要 单位时间。
请帮助 Farmer John 确定整个挤奶过程完成所需的最少时间,假设他以最佳方式配对奶牛。
输入格式
输入的第一行包含 ()。
接下来的 行每行包含两个整数 和 ,表示 Farmer John 有 头产奶量为 的奶牛()。所有 的总和为 ,即奶牛的总数。
输出格式
输出 Farmer John 的奶牛挤奶所需的最少时间,假设它们以最佳方式配对。
说明/提示
在这里,如果产奶量为 8 和 2 的奶牛配对,产奶量为 5 和 5 的奶牛配对,那么两个隔间的挤奶时间均为 10 单位时间。由于挤奶是同时进行的,因此整个挤奶过程将在 10 单位时间后完成。任何其他配对方式都会导致某个隔间的挤奶时间超过 10 单位时间,因此不是最优的。
3
1 8
2 5
1 2
10
提示
Here, if the cows with outputs 8+2 are paired up, and those with outputs 5+5 are paired up, the both stalls take 10 units of time for milking. Since milking takes place simultaneously, the entire process would therefore complete after 10 units of time. Any other pairing would be sub-optimal, resulting in a stall taking more than 10 units of time to milk.