#P5477. Chained Homework Scheduling

    ID: 18709 Type: Default 1000ms 256MiB

Chained Homework Scheduling

Chained Homework Scheduling

You are given a total of TT minutes to work on a series of homework assignments. There are nn assignments (numbered from 1 to nn). For the ii-th assignment, you are given three positive integers: its importance per copy viv_i, the time required to complete one copy tit_i, and the number of copies cic_i. In order to be considered fully completed for an assignment, you must complete all cic_i 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 kk copies with 1k<ci1\le k< c_i) 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 MM prerequisite relations. Each relation is described by two different numbers aa and bb, meaning that assignment aa is a prerequisite for assignment bb. 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 cic_i 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. tjt_j 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 cic_i 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 jj with the completed assignment as a prerequisite and if the remaining time is at least tjt_j, 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 kk copies with 1kci1\le k\le c_i) 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 TT minutes following the rules above.\n\nAll formulas are in (\LaTeX) format.

inputFormat

The input begins with a line containing three integers TT, nn, and MM, where TT is the total time available, nn is the number of assignments, and MM is the number of prerequisite relations.\n\nThen follow nn lines; the ii-th of these lines contains three integers viv_i, tit_i, and cic_i, representing the importance per copy, the time per copy, and the number of copies for assignment ii, respectively.\n\nThen follow MM lines; each line contains two integers aa and bb indicating that assignment aa is a prerequisite for assignment bb.

outputFormat

Output a single integer representing the maximum total importance you can achieve following the assignment rules within TT minutes.

sample

30 3 2
10 5 2
5 4 3
7 3 2
1 2
1 3
35

</p>