记录编号 605976 评测结果 AAAAAAAAAAAAAAAAAA
题目名称 4175.[USACO25 Feb Silver]The Best Lineup 最终得分 100
用户昵称 Gravatar彭欣越 是否通过 通过
代码语言 C++ 运行时间 2.590 s
提交时间 2025-09-13 15:23:31 内存使用 4.99 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000010;
int T,n,a[N];
struct node {
	int w,id;
}s[N];
bool cmp (node x,node y) {
	if (x.w==y.w) return x.id<y.id;
	return x.w>y.w;
}
int main () {
	freopen("Lineup.in","r",stdin);
	freopen("Lineup.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin >> T;
	while (T--) {
		int t1=0,t2=0,flag=0;
		cin >> n;
		for (int i=1;i<=n;i++) {
			cin >> a[i];
			s[i].w=a[i],s[i].id=i;
		}
		sort(s+1,s+1+n,cmp);
		for (int i=1;i<=n;i++) {
			//cout << t1 <<' '<< t2 <<endl;
			if (s[i].id>t2) {
				t1=t2;
				t2=s[i].id;
				cout << s[i].w <<' ';
			}else if (s[i].id>t1&&!flag) {
				flag=1;
				t2=s[i].id;
				cout << s[i].w <<' ';
			}
		}
		cout <<endl;
	}
	return 0;
}