#include<bits/stdc++.h>
using namespace std;
long long n, a[100005], cnt, b[10], ans, v[100005];
vector<int> num;
int calc() {
int mx = 0, mn = 100001, mxp, mnp;
for (int i = 1; i <= n; i++) {
if (v[i] == 1) continue;
if (a[i] > mx) mx = a[i], mxp = i;
if (a[i] < mn) mn = a[i], mnp = i;
}
int d = 0;
for (int i = min(mxp, mnp)+1; i <= max(mxp, mnp); i++) {
if (!v[i]) d++;
}
return d;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == n || a[i] == 1 || a[i] == n - 1 || a[i] == 2) {
b[++cnt] = i;
}
}
if (calc() > ans) {
ans = calc();
}
for (int i = 1; i <= cnt; i++) {
v[b[i]] = 1;
if (calc() > ans) {
ans = calc();
num.clear();
num.push_back(a[b[i]]);
}
v[b[i]] = 0;
}
for (int i = 1; i <= cnt; i++) {
for (int j = i + 1; j <= cnt; j++) {
if (i == j) continue;
v[b[i]] = v[b[j]] = 1;
if (calc() > ans) {
ans = calc();
num.clear();
num.push_back(a[b[i]]);
num.push_back(a[b[j]]);
}
v[b[i]] = v[b[j]] = 0;
}
}
cout << ans << endl;
if (num.size() > 0) {
sort(num.begin(), num.end());
for (auto it : num) {
cout << it << " ";
}
}
return 0;
}
天虹第3代码
最新推荐文章于 2024-11-04 19:24:37 发布