2015-2016 ACM-ICPC Excellence

题目地址:http://codeforces.com/gym/100819/attachments

题目:

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.

思路:

水题。

代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
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;
}

猜你喜欢

转载自blog.csdn.net/zero_979/article/details/80739000