Source Code
#include <bits/stdc++.h>

using namespace std;

#define all(v) (v.begin()), (v.end())
#define sor(x) sort(all(x))
#define pb(x) push_back(x)
#define fl(v, d) (memset(v, d, sizeof(v)))
#define len(s) ((int)s.size())
typedef long long ll;
typedef vector<int> vii;

#define MOD ll(1e9 + 7)
#define N (const ll)1e5 + 1

inline void solve()
{
    int n;
    cin >> n;
    pair<int, int> mx = {0, 0};
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (x > mx.first)
        {
            mx.first = x;
            mx.second = 0;
        }
        if (x == mx.first)
        {
            mx.second++;
        }
    }
    for (int i = 0; i < mx.second; i++)
    {
        cout << mx.first << ' ';
    }
    cout << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
Copy
To-do List Yazn_yousef
GNU G++17
74 ms
824 KB
Accepted