Untitled
unknown
plain_text
5 months ago
2.3 kB
4
Indexable
#include <bits/stdc++.h> using namespace std; #define int long long void __print(int x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned int x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif void solve() { int n,k; cin >> n >> k ; vector <int> a(n); for(int i=0;i<n;i++){ cin >> a[i]; } map <int,int> mp; for(int i=0;i<n;i++){ mp[a[i]]++; } vector <pair<int,int>> t; for(auto it : mp){ t.push_back({it.first,it.second}); } debug(t); vector <int> l; vector <int> r; int temp_l = -1; int temp_r = -1; int flag = 0 ; for(int i=0;i<t.size();i++){ if(t[i].second >= k && (t[i].first == t[i-1].first+1 || i ==0)){ if(flag == 0){ l.push_back(t[i].first); flag = 1; } else{ continue; } } else{ if(flag == 1){ r.push_back(t[i-1].first); flag = 0; } } } if(flag == 1){ r.push_back(t[t.size()-1].first); } debug(l,r); if(l.size() == 0){ cout << -1 << endl; return; } for(int i=0;i<l.size();i++){ if(r[i]-l[i]>temp_r-temp_l){ temp_l = l[i]; temp_r = r[i]; } } cout << temp_l << " " << temp_r << endl; } signed main() { int t = 1; cin >> t; while (t--) { solve(); } return 0; }
Editor is loading...
Leave a Comment