#P10541. Maximizing Profit with Technology and Product Dependencies
Maximizing Profit with Technology and Product Dependencies
Maximizing Profit with Technology and Product Dependencies
You are given a market scenario where launching certain products will yield profit, but each product requires a set of technologies. There are two ways to acquire a technology:
-
Purchase it directly at a cost of . This method does not require any prerequisites.
-
Develop (R&D) it at a cost of , but developing technology is only possible if all of its prerequisite technologies have already been acquired (by either method).
In addition, there are dependencies between products and technologies. There are products; launching the th product earns a profit of , but it can only be launched if all its prerequisite technologies are acquired. You are given pairs meaning that technology is required before launching product .
Furthermore, there are technologies and pairs representing technology–technology dependency: technology is a prerequisite for technology for the purpose of R&D acquisition. Note that the technology–technology dependency forms a directed acyclic graph (DAG), so no cycles occur.
A plan consists of selecting some products to launch (and hence acquiring the necessary technologies) and deciding for each required technology whether to purchase it or develop it. If a technology is acquired by development, all of its R&D prerequisites (according to the relations) must also be acquired by development. However, you may always opt to purchase a technology regardless of whether its prerequisites have been acquired.
The total profit is defined as the sum of the profits of the launched products minus the total cost of the technologies used. When a technology is required by more than one product, its cost is only paid once.
Your task is to output the maximum achievable profit.
Formally, let be the set of launched products and let be the set of required technologies (which must at least cover the prerequisites for every product in ). For each technology , you may acquire it by purchase at cost , or by R&D at cost provided that every technology with a dependency is also acquired by R&D. The goal is to maximize: [ \text{Profit} = \sum_{i\in S} g_i - \sum_{j\in T} \text{cost}(j), ] where ( \text{cost}(j) ) is chosen as described.
A common way to solve this problem is to reduce it to a maximum closure (or minimum cut) problem in a directed graph. In one typical formulation, you construct a graph where:
- Each product is represented with a profit (positive weight) , and an edge is added from the source to product with capacity .
- Each technology is represented with a cost (negative weight) of , and an edge is added from technology to the sink with capacity .
- For every product–technology dependency (meaning technology is required for product ), add an edge from product to technology with infinite capacity.
- For every technology–technology dependency (meaning technology is a prerequisite for developing technology ), add an edge from technology to technology with capacity . This edge effectively models the benefit (discount) of using R&D for technology when its prerequisite is also acquired by R&D.
The maximum closure value of this graph is equal to the maximum achievable profit. (Note that all formulas involving costs and profits must be written using LaTeX formatting.)
inputFormat
The input begins with four integers , , , and , where:
- is the number of products.
- is the number of technologies.
- is the number of product dependencies.
- is the number of technology dependencies.
The second line contains integers, , representing the profit of each product.
The third line contains integers, , representing the purchase cost for each technology.
The fourth line contains integers, , representing the R&D cost for each technology.
Then follow lines, each containing two integers and , indicating that technology is a prerequisite for product .
Finally, there are lines, each containing two integers and , indicating that technology is a prerequisite (for R&D) for technology .
All indices are 1-indexed.
outputFormat
Output a single integer: the maximum profit achievable.
sample
1 1 1 0
10
5
3
1 1
5