#P7374. [COCI 2018/2019 #5] Titlovi

[COCI 2018/2019 #5] Titlovi

Description

There is a .SRT file that consists of several subtitle blocks, which are loaded when watching a video. Each subtitle block has three parts:

  • Line 1: the subtitle index.
  • Line 2: subtitle start time --> subtitle end time.
  • The following several lines: subtitle text.

Here is an example subtitle file:

1
00:00:01,600 --> 00:00:04,200
Good day!

2
00:00:05,900 --> 00:00:07,999
Good day to you too!
Here you go!

3
00:00:10,000 --> 00:00:14,000
May I please have ten garlic sausages?

All times are given in the format HH:MM:SS,TTT, representing hours, minutes, seconds, and milliseconds. It is given that 11 second =1000= 1000 milliseconds.

Sometimes there may be a time offset during playback, so when loading the subtitles, you need to shift all subtitle times forward / backward by a specific amount of time, and output the adjusted .SRT file.

Input Format

The input contains at most 100100 lines, representing the content of a .SRT file.

For the first line of each subtitle block, the subtitle index is given. If the first block has index XX, then the ii-th block must have index X+i1X + i - 1.

Each subtitle block is separated by one empty line. Subtitle text contains English letters, spaces, and characters such as ,.?!., etc.

The line after the last line of the last subtitle block will contain a single character #, indicating the end of the subtitle section.

The next line / the last line of the input contains an integer TT, which is the time shift to apply. If T0T \ge 0, it means shifting the subtitle times backward by TT milliseconds. Otherwise, it means shifting the subtitle times forward by T-T milliseconds.

Output Format

Output the .SRT file after shifting the times.

8
00:00:01,600 --> 00:00:04,200
We thought you was...

9
00:00:05,900 --> 00:00:07,999
a toad.
#
300
8
00:00:01,900 --> 00:00:04,500
We thought you was...

9
00:00:06,200 --> 00:00:08,299
a toad.
#
624
00:43:30,566 --> 00:43:32,108
Howdy do, ladies?

625
00:43:32,276 --> 00:43:33,943
Name of Pete.

626
00:43:47,124 --> 00:43:48,082
Ain't you gonna
introduce us, Pete?
#
-500
624
00:43:30,066 --> 00:43:31,608
Howdy do, ladies?

625
00:43:31,776 --> 00:43:33,443
Name of Pete.

626
00:43:46,624 --> 00:43:47,582
Ain't you gonna
introduce us, Pete?
#

Hint

Constraints

For 100%100\% of the testdata, 104T104-10^4 \le T \le 10^4.

Notes

The score of this problem follows the original COCI settings, with a full score of 5050.

Note: After testing, the official input files may contain Windows-generated characters such as \r. Please pay attention to this during processing.

Translated from COCI2018-2019 CONTEST #5 T1 Titlovi.

Translated by ChatGPT 5