#P15772. [JAG 2025 Summer Camp #2] Driving Playlist
[JAG 2025 Summer Camp #2] Driving Playlist
题目描述
You are going to go driving with friends. To enjoy the driving, you have a playlist of songs numbered through .
At time you choose one of the songs and start it from its beginning. Then, the playlist repeats forever. For each (), once the song starts, it lasts units of of time, and then the song (or the song if ) follows immediately.
The -th friend, who loves the song , joins you at time . After that, they get excited whenever the song starts. Note that even if the song is already being played when they join you, they don't get excited because everyone wants to enjoy their favorite song from the beginning.
If you choose the first song to play optimally, when is the earliest time that all the friends get excited at least once? Note that you cannot start playing a song from the middle.
输入格式
The input consists of a single test case of the following format.
$$\begin{aligned} & n \ m \\ & l_1 \ l_2 \ \cdots \ l_n \\ & t_1 \ t_2 \ \cdots \ t_m \\ & f_1 \ f_2 \ \cdots \ f_m \end{aligned} $$The first line contains two integers and (, ). is the number of songs in the playlist and is the number of friends who join your driving.
The second line contains positive integers . Each represents the length of the song . Their sum does not exceed .
The third line contains integers (). Each represents that the -th friend joins you at time .
The fourth line contains integers (). Each is the number of the favorite song of the -th friend.
输出格式
Output an integer, which is the earliest time that all the friends get excited at least once.
3 4
3 1 4
10 7 3 7
1 3 2 1
12
5 7
20 25 9 14 20
25 9 14 75 38 100 38
3 1 1 5 2 4 4
136
提示
In the first sample, if you start the playlist from song , the four friends first get excited at times , , , and , respectively.