天虹第3代码

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值