记录编号 605984 评测结果 AAAAAAAAAAAAAAAAAA
题目名称 4175.[USACO25 Feb Silver]The Best Lineup 最终得分 100
用户昵称 GravatarLikableP 是否通过 通过
代码语言 C++ 运行时间 3.880 s
提交时间 2025-09-13 16:04:44 内存使用 4.54 MiB
显示代码纯文本
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 2e5 + 10;

int T;
int n;
pair<int, int> a[MAXN];

int main() {
  freopen("Lineup.in", "r", stdin);
  freopen("Lineup.out", "w", stdout);
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i].first;
      a[i].second = i;
    }
    
    sort(a + 1, a + n + 1, [](auto x, auto y) {
      if (x.first != y.first) return x.first > y.first;
      return x.second < y.second;
    });
    
    int prepre = 0, pre = 0, flag = 0;
    for (int i = 1; i <= n; ++i) {
      int val = a[i].first, id = a[i].second;
      if (id > pre) {
        prepre = pre, pre = id;
        cout << val << " ";
      } else if (!flag && prepre < id) {
        pre = id, flag = 1;
        cout << val << " ";
      }
    }
    
    cout << endl;
  }
  return 0;
}