| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 128 MB | 9 | 6 | 2 | 40.000% |
A large governmental project usually consists of several modules that require different expertise and investment. The requirements make it difficult for a single company to finish the project on its own. Therefore, two or more companies tend to work together in order to share expertise and resources. This is a common practice for joint venture. Unfortunately, maximizing the joint-venture profit is not trivial because there are many factors we need to consider. This is where a computer program comes to the play.
Suppose that Companies A and B are working together in a joint venture that needs to be finished within $D$ days. The project consists of $M$ modules ($L_1, L_2, \dots , L_M$). In addition, Module $L_1$ must be the first to finish, while Module $L_i$ must be finished before Module $L_{i+1}$ can be started, where $i ≥ 1$. Assume further than a subsequent module $L_{i+1}$ can be started the next day once its prior module $L_{i}$ is finished. Also, a certain module will be handled by either A or B, not both.
Since Companies A and B have different sets of expertise, Company A may be able to finish a certain module with relatively small amount of time and money, while Company B may need much more time and money and vice versa. It is also possible that one of the companies cannot work on a specific module. This forces another company to work on the module in order to have a chance to finish the project.
Regarding your task, you need to develop an efficient algorithm to find how A and B should share their work to meet project requirements (finish all $M$ modules within the number of days $D$) and maximize the profit from this joint venture.
The first line contains a positive integer $T ≤ 10$ representing the number of projects that Companies A and B are working together. For each project, the following data are provided. It is important to note that all numbers in the same line are separated by one white space.
Your program will print out $T$ integers representing the ma imum profit of Projects 1,ドル 2, \dots,$ and $T,ドル respectively. Each integer is separated by a white space. If a joint venture cannot fulfill the requirement because both A and B cannot work on a specific module or because there is no way to finish the project in time limit $D,ドル your program will print $-1$. If a joint venture cannot generate profit (loss or break even), your program will also print $-1$. Otherwise, your program will print the maximum profit of the project in million Thai bahts.
5 200 4 10 5 4 5 8 -1 10 100 200 100 50 1 2 -1 3 1 3 2 2 150 4 10 6 4 5 8 -1 10 100 200 100 50 1 2 -1 3 1 3 2 2 150 4 7 10 10 5 8 -1 10 100 200 100 50 1 2 -1 2 1 3 2 2 100 4 50 10 10 5 8 -1 10 100 200 100 50 1 2 -1 3 1 3 2 2 200 4 50 10 10 5 8 -1 10 100 200 -1 50 1 2 -1 3 1 3 -1 2
3 2 -1 -1 -1