Cranes
InterviewTime limit1sMemory limit128 MB
Choose a subset of at most 15 crane locations, each with a radius, so that every pair's distance exceeds the sum of radii, maximizing the total squared radius.
- Level
Medium6 of 10
- Topics
- Brute force, Geometry, Backtracking, Implementation
- Solved
- No attempts yet
Problem
A crane is a great tool for putting up a building, and using several cranes makes construction go even faster. But when too many cranes work on the same building they can become dangerous: as a crane spins around it can bump into another crane and topple over, causing serious damage. Safety rules therefore require the cranes to be spaced far enough apart that no part of one crane can ever touch any part of another crane.
The construction site is a square grid, and several grid points are marked as possible crane locations. A crane placed at a location has an arm of length that rotates around that location, so it covers every point within distance of the location (a disk of radius ). Two placed cranes are allowed together only if their disks never touch, that is, the distance between their locations is strictly greater than the sum of their arm lengths.
Respecting the safety rule, choose which of the marked locations to place cranes on so that the total area covered by all the placed cranes is as large as possible.
Input
The first line contains an integer , the number of test cases. Each test case starts with a line containing an integer , the number of possible crane locations, with . Each of the next lines contains three integers , , and , each between and inclusive: are the grid coordinates of the location and is the arm length of the crane that can be placed there.
Output
For each test case, let be the maximum total area that can be covered while respecting the safety rule. Output one line with the integer such that . Because a crane covers an area of and the placed disks never overlap, equals the largest possible sum of over a set of cranes chosen so that none of them touch.