## Description

## Submission

class Solution {
public:
vector<int> smallestRange(vector<vector<int>>& nums) {
set<pair<int,int>> Set;
int n = nums.size();
vector<int> pointers(n, 0);
for(int i = 0; i < n; ++i) {
Set.insert({nums[i][0], i});
}
int r = INT_MAX;
vector<int> ret;
while(true) {
if(Set.rbegin()->first - Set.begin()->first < r) {
r = Set.rbegin()->first - Set.begin()->first;
ret = {Set.begin()->first, Set.rbegin()->first};
}
int i = Set.begin()->second;
pointers[i]++;
if(pointers[i] == nums[i].size()) break;
Set.erase(Set.begin());
Set.insert({nums[i][pointers[i]], i});
}
return ret;
}
};