include
class Solution {
public:
/**
*
* @param n int整型
* @param k int整型
* @param card int整型vector<vector<>>
* @return int整型
*/
int solve(int n, int k, vector<vector<int> >& card) {
int r = INT_MAX;
sort(card.begin(), card.end(), [](vector<int>& a, vector<int>& b){return a[1]<b[1];});
unordered_map<int, int> M;
for(int i=0,j=0;j<n;j++){
M[card[j][0]]++;
while(i<j && M.size()==k){
r = min(r, card[j][1]-card[i][1]);
if(--M[card[i][0]] == 0)
M.erase(card[i][0]);
i++;
}
}
return r==INT_MAX?-1:r;
}
};</int></int></int>