Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(l) cerr<<#l<<' '<<l<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(pref) pref.begin(), pref.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef long double ld;
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- ll t;
- cin >> t;
- while (t--) {
- ll n, k;
- cin >> n >> k;
- vector<ll> a(n);
- map<ll, ll> cnt;
- for (ll i = 0; i < n; i++) {
- cin >> a[i];
- cnt[a[i]]++;
- }
- sort(all(a));
- a.resize(unique(all(a)) - a.begin());
- ll ans = -1;
- pll cur;
- n = a.size();
- for (ll l = 0; l < n; l++) {
- if (cnt[a[l]] >= k) {
- ll r = l;
- while (r < n && cnt[a[r]] >= k && a[(r==l?l:r)] - a[(r==l?l:r-1)] <= 1)r++;
- r--;
- if (a[r] - a[l] > ans) {
- ans = a[r] - a[l];
- cur = { a[l],a[r] };
- }
- l = r;
- }
- }
- if (ans == -1) {
- cout << ans << '\n';
- }
- else {
- cout << cur.first << ' ' << cur.second << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement