[Solution] Cute Little Butterfly Round G 2022 Solution - Kick Start 2022
Problem
In a forest of the magical world, there lies a garden full of magical creatures. The garden has plenty of flowers which are not just beautiful but also a source of energy for butterflies.
Consider the garden a 2D plane where the X-axis represents the ground, and the Y-axis represents the altitude. There are plants of infinite height on every non-negative integral point on the X-axis. There are flowers in the garden, where the -th flower is on the point (, ) with the nectar of some energy value .
Our cute little butterfly wants as much energy as possible to become strong. By going to the same position of a flower, the butterfly can consume its nectar and gain that flower's energy value. Each flower's nectar can only be consumed once.
The butterfly is initially at point with units of energy and facing towards the right. At any point, the butterfly can:
- Move to a lower altitude, that is, from to only if its current altitude is positive ().
- Move in the positive direction along the X-axis, that is, from to if it is facing right.
- Move in the negative direction along the X-axis, that is, from to if it is facing left.
- Change the direction it is facing (from left to right or vice versa). This will consume units of energy.
We know our butterfly is lazy, and it hates to move upwards during the journey. So, for this problem, we will assume that going upwards is not allowed. Also, energy can be negative at any point. Negative energy means the butterfly has spent more energy than it obtained from the flowers.
Find the maximum energy our cute butterfly can achieve.
Input
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains two integers, and : the number of flowers and the energy required per turn, respectively.
The next lines describe the flowers. The -th line contains three integers, , and : the position and the energy value of the -th flower, respectively.
Output
For each test case, output one line containing Case #:
, where is the test case number (starting from 1) and is the maximum overall energy our cute butterfly can achieve.
Limits
Memory limit: 1 GB.
.
.
, for all .
All flowers are located at distinct points.
Test Set 1
Time limit: 20 seconds.
.
, for all .
, for all .
Test Set 2
Time limit: 40 seconds.
.
, for all .
, for all .
Test Set 3
Time limit: 60 seconds.
, for all .
, for all .
For at most 10 cases:
.
For the remaining cases:
.
No comments:
Post a Comment