Make the team
InterviewTime limit1sMemory limit1024 MB
Assign each video a distinct whole-hour start time so that the latest finish time is as early as possible.
- Level
Medium5 of 10
- Topics
- Graph, Binary search
- Solved
- No attempts yet
Problem
You want to join the programming team, and you believe that watching several videos will improve your chances. Each video is one hour long and plays only at specific times. You want to finish watching all the videos as early as possible so you have more time to practice.
For example, suppose you want to watch two videos. The first video plays during , , , and . The second video plays during , , and . The earliest time you can finish both is 5. Watch the first video during and the second video during . Every video lasts exactly as long as one playback interval. You can watch back-to-back videos. If one video plays during and another plays during , where is a positive integer, you can watch both in sequence.
Given the times each video is available, find the earliest time you can finish watching all the videos. The videos can be watched in any order as long as the intervals allow it.
Input
The first line contains one integer (), the number of videos. Each of the next lines describes one video. The -th line starts with an integer (), the number of times video is available, followed by space-separated start times. The start times for each video form a strictly increasing list of positive integers, with a maximum value of 1000. It is guaranteed that at least one arrangement lets you watch all the videos.
Output
Print the earliest time at which you can finish watching all the videos.