Advertisement
ivnikkk

Untitled

May 10th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS  
  2. #define debug(l) cerr<<#l<<' '<<l<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(pref) pref.begin(), pref.end()
  6. typedef long long ll;
  7. typedef pair<ll, ll> pll;
  8. typedef long double ld;
  9. signed main() {
  10. #ifdef _DEBUG
  11.     freopen("input.txt", "r", stdin);
  12.     freopen("output.txt", "w", stdout);
  13. #endif
  14.     ios_base::sync_with_stdio(false);
  15.     cin.tie(nullptr);
  16.     cout.tie(nullptr);
  17.     ll t;
  18.     cin >> t;
  19.     while (t--) {
  20.         ll n, k;
  21.         cin >> n >> k;
  22.         vector<ll> a(n);
  23.         map<ll, ll> cnt;
  24.         for (ll i = 0; i < n; i++) {
  25.             cin >> a[i];
  26.             cnt[a[i]]++;
  27.         }
  28.         sort(all(a));
  29.         a.resize(unique(all(a)) - a.begin());
  30.         ll ans = -1;
  31.         pll cur;
  32.         n = a.size();
  33.         for (ll l = 0; l < n; l++) {
  34.             if (cnt[a[l]] >= k) {
  35.                 ll r = l;
  36.                 while (r < n && cnt[a[r]] >= k && a[(r==l?l:r)] - a[(r==l?l:r-1)] <= 1)r++;
  37.                 r--;
  38.                 if (a[r] - a[l] > ans) {
  39.                     ans = a[r] - a[l];
  40.                     cur = { a[l],a[r] };
  41.                 }
  42.                 l = r;
  43.             }
  44.         }
  45.         if (ans == -1) {
  46.             cout << ans << '\n';
  47.         }
  48.         else {
  49.             cout << cur.first << ' ' << cur.second << '\n';
  50.         }
  51.  
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement