Excellence(水题)

Description

The World Coding Federation is setting up a huge online programming tournament of teams comprisedof pairs of programmers. Judge David is in charge of putting teams together from theSoutheastern delegation. Every student must be placed on exactly one team of two students.Luckily, he has an even number of students who want to compete, so that he can make sure thateach student does compete. However, he’d like to maintain his pristine reputation amongst otherjudges by making sure that each of the teams he fields for the competition meet some minimumtotal rating. We define the total rating of a team to be the sum of the ratings of both individualson the team.

Help David determine the maximum value, X, such that he can form teams, each of which havea total rating greater than or equal to X.

Input

The first line of input contains a single positive integer n (1 ≤ n ≤ 105, n is even), the numberof students who want to enter the online programming tournament. Each of the following n linescontains one single integer si (1 ≤ si ≤ 106), the rating of student i.

Output

Print, on a single line, the maximum value, X, such that David can form teams where every teamhas a total rating greater than or equal to X.

Sample Input

4

1

2

3

5

Sample Output

5

Sample Input

2

18

16

Sample Output

34

Sample Input

4

13

12

19

14

Sample Output

27

题解:对所有分数排序,前后对应相加,取最小的值。

代码如下:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
    int m,n,a[1111111];
    cin>>n;
    for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int min=0x3f3f3f3f;
	for(int i=0;i<n/2;i++)
		if(min>a[i]+a[n-i-1])
			min=a[i]+a[n-i-1];
	cout<<min<<endl;
    return 0;
}









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值