#BF0000040. Lập lịch công việc có phụ thuộc (Schedule Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lập lịch công việc có phụ thuộc (Schedule Problem)
Schedule Problem
Source: HDU
Version: Phuoc Hung OJ Extended
Problem Statement
There are tasks with continuous durations . Relations are FAS a b (finish of no earlier than start of ), FAF a b (finish of no earlier than finish of ), SAF a b (start of no earlier than finish of ), SAS a b (start of no earlier than start of ). Tasks may overlap. Print a schedule minimizing project completion time, or impossible if no schedule exists.
The finish time of task is ; the project completion time is . The minimum start time must be .
This Extended version uses explicit and no terminating sentinel.
Input
First line . Next are durations , followed by lines TYPE a b, with TYPE one of FAS, FAF, SAF, SAS.
Output
Print impossible if infeasible; otherwise print lines i T_i in increasing task index, with nonnegative starts .
Subtasks
- Subtask 1 (20 points): $2\le n\le12; 0\le m\le30; 1\le d_i\le100; 1\le a,b\le n; a\ne b$.
- Subtask 2 (30 points): $2\le n\le70; 0\le m\le400; 1\le d_i\le1000; 1\le a,b\le n; a\ne b$.
- Subtask 3 (50 points): $2\le n\le300; 0\le m\le2500; 1\le d_i\le100000; 1\le a,b\le n; a\ne b$.
Examples
Input
3 2
2 3 4
SAF 2 1
FAF 3 2
Output
1 0
2 2
3 1
Explanation
SAF 2 1 gives . FAF 3 2 yields , or . The starts satisfy both and finish the project in time units.