Timeline
Time limit2sMemory limit512 MB
Given lower bounds on each of N session dates and C constraints that one session is at least x days after another, find the earliest feasible date for every session.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Dynamic programming, Topological sort
- Solved
- No attempts yet
Problem
Bessie attended milking sessions () over the past days (). However, she is having trouble remembering when she attended each session.
For each session , she knows that it occurred no earlier than day (). Additionally, Bessie has memories (), each described by a triple , where she recalls that session happened at least days after .
Help Bessie by computing the earliest possible date of occurrence for each milking session. It is guaranteed that Bessie did not remember incorrectly; in other words, there exists an assignment of sessions to days in the range such that all constraints from her memories are satisfied.
Input
The first line of input contains , , and .
The next line contains space-separated integers . Each is in the range .
The next lines contain three integers, , , and indicating that session happened at least days after . For each line, , and are in the range , and is in the range .
Output
Output lines giving the earliest possible date of occurrence for each session.
Hint
Session two occurred at least five days after session one, so it cannot have occurred before day . Session four occurred at least two days after session two, so it cannot have occurred before day .