Use multimap to store each element in the two-dimensional vector in the form of (element value, group). Since the element value may be repeated, the multmap is used to store it here.
Use the sliding window to linearly traverse the stored elements in the multimap from the beginning to the end, and use a map to record how many groups of elements have been traversed.
When it is detected that map.size() contains each group, the left end of the window is reduced, and the minimum difference between the left end and the right end is recorded during the process.