#K73812. Fair Gardening Event Scheduling
Fair Gardening Event Scheduling
Fair Gardening Event Scheduling
Tina is organizing a communal gardening event in her neighborhood. In order to ensure fairness, each participant must be allocated the same amount of time to plant trees and the same total number of trees to plant.
Each participant is given several independent time slots for planting. A time slot is represented by a pair of consecutive integers indicating a start time and an end time. Specifically, the duration of each time slot is constant (i.e. from time t to t+1). The scheduling ensures that the time allocated to each participant is the same.
Given T test cases, where each test case provides:
- n: the number of participants
- m: the number of trees each participant has to plant (which equals the number of time slots assigned per participant)
The task is to generate a schedule following these rules:
- For each test case, first output a line containing the total number of slots, which is given by \(n\times m\).
- Then, for each participant (numbered from 1 to \(n\)), output exactly \(m\) lines. Each line represents a slot in the format:
participant start_time end_time
wherestart_time
starts at 1 for each participant and increments by 2 for each subsequent slot (i.e. the slots for a participant will be 1 2, 3 4, 5 6, ... etc.).
For example, if there are 2 participants (n=2) and each must plant 3 trees (m=3), the first test case output should be:
6 1 1 2 1 3 4 1 5 6 2 1 2 2 3 4 2 5 6
This scheduling guarantees that all participants have an equal amount of planting time; mathematically, each receives \(m\) slots and the total number of slots is \(n\times m\).
inputFormat
The input is read from stdin and has the following format:
T n1 m1 n2 m2 ...
where:
T
is the number of test cases.- Each of the following T lines contains two integers
n
andm
separated by a space, wheren
is the number of participants andm
is the number of trees each participant must plant.
outputFormat
The output should be written to stdout with the following format for each test case:
X p1 s1 s2 p1 s3 s4 ... (m lines for participant 1) ... pn s? s?
Where:
X
is the total number of slots (i.e. \(n \times m\)).- Each subsequent line describes a time slot in the format
participant start_time end_time
with the participant number followed by its start and end times. - The start times for each participant begin at 1 and increase by 2 for each subsequent slot.
2
2 3
3 4
6
1 1 2
1 3 4
1 5 6
2 1 2
2 3 4
2 5 6
12
1 1 2
1 3 4
1 5 6
1 7 8
2 1 2
2 3 4
2 5 6
2 7 8
3 1 2
3 3 4
3 5 6
3 7 8
</p>