#C4451. Continuous Periods Finder

    ID: 47991 Type: Default 1000ms 256MiB

Continuous Periods Finder

Continuous Periods Finder

You are given a sequence of events. Each event consists of a timestamp and an event type. Your task is to find all continuous periods where the event type matches a given target and the events occur in consecutive integer timestamps, lasting at least a specified duration.

A continuous period is defined as a maximal sequence of events where the timestamps are consecutive (i.e., for any two adjacent events, the difference between their timestamps is 1) and each event's type is equal to the specified target event type. If the number of events in such a sequence is greater than or equal to the given duration, then the period is valid.

Input/Output Format:

The input is read from stdin and the output is written to stdout.

If no valid continuous period exists, output -1.

Examples:

Example 1:
Input:
1 2 8
1 1
2 1
3 1
6 1
7 1
8 2
10 1
11 1

Output: 1 3 6 7 10 11

Example 2: Input: 2 1 7 1 2 2 2 4 2 6 1 7 2 10 2 11 2

Output: 1 2 4 4 7 7 10 11

</p>

inputFormat

The first line contains three integers separated by spaces: T (the target event type), D (the minimum required duration), and N (the number of events).

Each of the following N lines contains two integers: timestamp and event_type.

It is guaranteed that the events are given in ascending order of timestamps.

outputFormat

For each continuous period that meets the criteria, output a line with two integers: the start and end timestamps of that period.

If no valid period is found, output a single line containing -1.

## sample
1 2 8
1 1
2 1
3 1
6 1
7 1
8 2
10 1
11 1
1 3

6 7 10 11

</p>