luogu#P5477. [MtOI2018] 刷题?作业狂魔!

[MtOI2018] 刷题?作业狂魔!

Background

After hearing that summer vacation is coming to an end, the magical cz finally realized that he cannot finish his homework.

Before he finishes the homework, you need to tell him the order in which to do it, so that you can play together.

Problem Description

You have TT minutes.

The order of doing homework can be sorted by importance viv_i, but this may not be the best strategy. Also, each type of homework may have more than one item, so each homework also has a quantity cic_i, and each item takes tit_i minutes to complete.

Before doing some homework, it may be necessary to finish some other homework first, so MM relations are given. Each relation contains two numbers aa, bb, meaning that aa is a prerequisite for completing bb. There is no case where a=ba=b.

The relations may contain cycles. cz does not want to redo homework, so he can only skip the homework that lies on cycles.

If the time ends when a homework is only half done, then you gain no importance from that homework. If for a homework you finish only kk items, and kcik\leq c_i, then you gain k×vik\times v_i importance. If you do not finish all cic_i items of that homework, then you are not allowed to do any other homework.

A homework bb may have multiple prerequisites aa. However, note that once one prerequisite of a homework is done, that homework can be done. But cz is very focused: after finishing one homework, he must do the homework that uses this homework as a prerequisite.

Input Format

The input has N+M+2N+M+2 lines.

Line 11 contains two positive integers N,TN,T.

The next NN lines follow. Line ii contains three positive integers vi,ci,tiv_i,c_i,t_i.

Line N+2N+2 contains one positive integer 11.

The next MM lines describe the relations, with the same meaning as above.

Output Format

Output one line with one number, the maximum value (importance).

4 7
2 1 1
2 1 2
2 1 3
2 1 4
3
3 4
2 3
1 2
6

Hint

Subtasks

For 100%100\% of the testdata, 1<=N<=10000,1<=M<=1000001<=N<=10000,1<=M<=100000.

All other values are within the range of longlonglong long.

Source

MtOI2018 迷途の家の水题大赛 T1

Problem setter: Doubleen

56432

Translated by ChatGPT 5