4.2 Cosmic Bioengineering
Some bioengineers are tasked with optimizing the growth of Celestial Vines in a constrained environment. Each vine species has an enigmatic Cosmic Yield which can be maximized through an optimal allocation of three cosmic resources: Stardust, Photon Rays, and Quantum Essence. Each species has specific requirements for these resources and provides a mysterious Galactic Energy when fully nurtured.
To maximize the total Galactic Energy, you need to determine the fractional allocation of resources to each species based on their Galactic Efficiency Ratio which combines their requirements and yields. You have a limited amount of each resource and need to allocate them wisely.
Constraints
1≤n≤10
1≤𝑆𝑅,𝑃𝑅,𝑄𝑅≤100
1≤SR,PR,QR≤100
1≤𝐶𝑌≤1000
1≤CY≤1000
1≤𝑇𝑆,𝑇𝑃,𝑇𝑄≤1000
1≤TS,TP,TQ≤1000
Input Format
>An integer n (the number of vine species).
>Three resource limits:
Total Stardust Available (TS).
Total Photon Rays Available (TP).
Total Quantum Essence Available (TQ).
>For each vine species, the following values:
Stardust Requirement (SR): The amount of Stardust needed for full growth.
Photon Rays Requirement (PR): The amount of Photon Rays needed for full growth.
Quantum Essence Requirement (QR): The amount of Quantum Essence needed for full growth.
Cosmic Yield (CY): The total Galactic Energy produced if the vine is fully grown.
Output Format
The total Galactic Energy produced from the allocated resources.
Example 1
Input:
4
100 100 100
40 20 10 280
10 5 5 100
20 15 5 120
24 10 10 120
Output:
620.00
Explanation:
In the test case, the vines are sorted based on their Galactic Efficiency Ratio (yield per unit of resources). Initially, 100 units each of stardust, photon, and essence are available. The algorithm first tries to fully allocate resources to the vine with the highest efficiency. If a vine requires more resources than available, a fraction of the resources is allocated proportionally to maximize energy yield. The total energy calculated is the sum of the vine yields, adjusted for fractional resource allocations where necessary.
Log In to solve the Question