You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
678 B

#include <bits/stdc++.h>
using namespace std;
int main() {
//cin读入优化
std::ios::sync_with_stdio(false);
//输入+输出重定向
freopen("../number.in", "r", stdin);
freopen("../number.out", "w", stdout);
int n;
cin >> n;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a.begin() + 1, a.end());
//两两对比,找最大值
int maxx = -1;
for (int i = 1; i <= n / 2; i++) {
if (a[i] + a[n - i + 1] > maxx) maxx = a[i] + a[n - i + 1];
}
cout << maxx << endl;
//关闭文件
fclose(stdin);
fclose(stdout);
return 0;
}