[Solution] Lemonade Life Meta Hacker Cup Round 1 Solution 2022
There's a famous saying about what to do when life gives you lemons. As a traveling lemonade salesman who's never been given any lemons, you sadly can't relate. You must shamefully concoct your lemonade from store-bought powder with your back turned to the world, lest someone see your dirty secret.
Your sales route can be mapped out on a Cartesian plane with houses, the th of which is at coordinates . Your journey starts at house , the leftmost house, and ends at house , the rightmost house. Along the way, you may stop at zero or more other houses to sell lemonade.
You may only stop at a house if:
- there is a direction you can face in which all other houses would be strictly more behind you than they are in front of you (formally, if there exists a half-plane containing only house ), and
- house is at most Euclidean distance from the previous house you were at.
Your brand image is hurt if you go too long without selling lemonade. The brand damage incurred by traveling from one house to another is the larger of and the squared Euclidean distance between them. Formally, if your journey consists of houses with the th being house , the total brand damage is:
Is it possible to make the journey? If so, what is the minimum possible total brand damage to do so? Note that the answer may be large, but will fit in a 64-bit integer.
Constraints
is strictly less than all other .
is strictly greater than all other .
All are distinct within a given test case.
The sum of across all test cases is at most .
There are at most test cases in which .
Input Format
Input begins with a single integer , the number of test cases. For each test case, there is first a line containing three space-separated integers , , and . Then, lines follow, the th of which contains two space-separated integers and .
Output Format
For the th test case, print a line containing "Case #i: " followed a single integer, the minimum total brand damage that must be incurred to make the journey, or if it's impossible to do so.
Sample Explanation
The first three sample cases are depicted below, with the optimal paths given in blue.
In the first case, going from one house to another takes at least brand damage and must not exceed a distance of . The total brand damage is . Note that you cannot stop at house because there is no direction you could face from there in which your back is at least slightly facing both house and .
In the second case, you can stop at house because for instance, the line contains only , and the half-plane below it contains no other houses.
In the third case, you cannot stop at house . There are no other houses within units of your starting house, so it is not possible to reach the house at .
No comments:
Post a Comment