#K10451. Resource Allocation Management
Resource Allocation Management
Resource Allocation Management
You are given a scheduling system where N employees request access to M resources. Each request is represented as a tuple of four integers: employee ID, resource ID, start time, and duration.
A request is valid if it does not overlap with any previously accepted request for the same resource. Two requests for the same resource are said to overlap if their time intervals intersect. Formally, for a request with start time s and duration d, its time interval is \( [s, s+d) \). Two intervals \( [s_1, s_1+d_1) \) and \( [s_2, s_2+d_2) \) are non-overlapping if and only if \( s_1+d_1 \leq s_2 \) or \( s_2+d_2 \leq s_1 \).
Your task is to process the requests in the given order. If a request does not conflict with any previously accepted request for the same resource, accept it and update the resource's schedule; otherwise, discard it. Finally, output all the valid requests in the order they were accepted.
inputFormat
The input is read from standard input (stdin
) and has the following format:
- The first line contains two integers,
N
(the number of employees) andM
(the number of resources). - The second line contains an integer
K
, the number of requests. - This is followed by
K
lines, each containing four space-separated integers:employee_id
,resource_id
,start_time
, andduration
.
outputFormat
Output the valid requests to standard output (stdout
). Each valid request should be printed on a separate line as four space-separated integers in the order: employee_id resource_id start_time duration
.
3 2
4
1 1 60 30
2 1 80 20
3 1 75 25
2 2 100 50
1 1 60 30
2 2 100 50
</p>