#K65687. Maximizing Total Beauty in a Flower Garden
Maximizing Total Beauty in a Flower Garden
Maximizing Total Beauty in a Flower Garden
John is an enthusiastic gardener who loves to plant a row of beautiful flowers. He has n different types of flowers. Each flower type is represented by four integers: g_min, g_max, h, and b. Here, g_min and g_max denote the minimum and maximum growth times (in days) during which the flower blooms, h denotes the height (in centimeters) of the flower, and b denotes its beauty score.
John wants to plant a sequence of flowers under the following conditions:
- You may select any number of flowers (including the possibility of selecting none).
- You can start with any type of flower.
- The heights of the planted flowers must be in strictly increasing order.
- The growth periods of any two consecutive flowers must overlap by at least one day. Mathematically, if flower i precedes flower j in the sequence, then it must hold that:
\[ h_i < h_j \quad \text{and} \quad g_{max}^{(i)} \geq g_{min}^{(j)} - 1 \]</p>Your task is to determine the sequence that maximizes the total beauty score while adhering to the above rules.
Input Constraints:
- n (number of flower types) is a positive integer.
- For each flower type, four integers are provided: g_min, g_max, h, and b.
inputFormat
The first line contains a single integer n, representing the number of flower types.
The following n lines each contain four space-separated integers: g_min, g_max, h, and b, corresponding to the minimum growth time, maximum growth time, height, and beauty score of a flower.
outputFormat
Output a single integer representing the maximum total beauty score that can be achieved by planting a valid sequence of flowers under John's rules.
## sample3 1 5 10 20 3 8 15 30 2 6 12 25
75