Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: E. Beautiful Palindromes
- // Contest: Codeforces - Codeforces Round 1059 (Div. 3)
- // URL: https://codeforces.com/contest/2162/problem/E
- // Memory Limit: 256 MB
- // Time Limit: 2000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- namespace rngs = std::ranges;
- using ll = long long;
- using a2l = array<ll, 2>;
- using vl = vector<ll>;
- void solve()
- {
- ll n, k;
- cin >> n >> k;
- vl a(n);
- for (auto &x : a)
- cin >> x;
- set<ll> ss(a.begin(), a.end());
- vl opts;
- if (ss.size() + 2 <= n) {
- for (ll i = 1; i <= n && opts.size() < 3; ++i)
- if (ss.count(i) == 0)
- opts.push_back(i);
- if (opts.size() != 3)
- opts.push_back(a.back());
- dbg(opts);
- } else if (ss.size() + 1 == n) {
- ll x = -1, y = -1, z = a.back();
- for (ll i = 1; i <= n; ++i)
- if (ss.count(i) == 0)
- x = i;
- y = a[n - 1] == a[n - 2] ? a[n - 3] : a[n - 2];
- opts = vl{x, y, z};
- dbg(opts);
- } else {
- opts = vl{a[n - 3], a[n - 2], a[n - 1]};
- dbg(opts);
- }
- // cout << k << '\n';
- for (ll i = 0; i < k; ++i)
- cout << opts[i % 3] << ' ';
- cout << '\n';
- }
- int main(int argc, char **argv)
- {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- ll t = 1;
- cin >> t;
- while (t--)
- solve();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment