#P5477. Chained Homework Scheduling
Chained Homework Scheduling
Chained Homework Scheduling
You are given a total of minutes to work on a series of homework assignments. There are assignments (numbered from 1 to ). For the -th assignment, you are given three positive integers: its importance per copy , the time required to complete one copy , and the number of copies . In order to be considered fully completed for an assignment, you must complete all copies; doing so yields a total importance of $$c_i \times v_i.$$ However, you are also allowed to do only a partial number of copies (say copies with ) of an assignment; in that case you obtain $$k \times v_i$$ importance but you are not allowed to work on any further assignments afterwards. Moreover, if you start an assignment and run out of time before finishing a copy, you gain no importance from that assignment.\n\nThere are also prerequisite relations. Each relation is described by two different numbers and , meaning that assignment is a prerequisite for assignment . Note: An assignment becomes available to work on once any one of its prerequisites is completed. However, once you finish an assignment completely (i.e. doing all copies), if there exists at least one assignment that has it as a prerequisite and there is enough remaining time to do at least one copy of that assignment (i.e. minutes), you are forced to continue your work by starting one of those assignments. In other words, in a valid work plan you form a chain of assignments such that: \n\n1. You start with an assignment that does not require any prerequisite (or whose prerequisites have been removed as described below).\n2. For every assignment in the chain except the last one, you must do all its copies (using $$c_i \times t_i$$ minutes and obtaining $$c_i \times v_i$$ importance).\n3. After fully completing an assignment, if there is any assignment with the completed assignment as a prerequisite and if the remaining time is at least , you must choose one such assignment to continue.\n4. For the last assignment in the chain you are allowed to do a partial work (i.e. do copies with ) provided that you cannot or do not wish to continue with a dependent assignment.\n\nAn additional twist is that the prerequisite relations may contain cycles. In such cases, you choose not to work on any assignment that is part of a cycle.\n\nYour task is to find the maximum total importance that you can achieve within minutes following the rules above.\n\nAll formulas are in (\LaTeX) format.
inputFormat
The input begins with a line containing three integers , , and , where is the total time available, is the number of assignments, and is the number of prerequisite relations.\n\nThen follow lines; the -th of these lines contains three integers , , and , representing the importance per copy, the time per copy, and the number of copies for assignment , respectively.\n\nThen follow lines; each line contains two integers and indicating that assignment is a prerequisite for assignment .
outputFormat
Output a single integer representing the maximum total importance you can achieve following the assignment rules within minutes.
sample
30 3 2
10 5 2
5 4 3
7 3 2
1 2
1 3
35
</p>