Love for Pizza
Time limit2sMemory limit1024 MB
Given each topping's preference and center point on a pizza, find the maximum total preference of one wedge cut from the pizza.
- Level
Medium5 of 10
- Topics
- Geometry, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
My brother and I love pizza. Today my brother ordered a pizza with a number of toppings. I like some toppings, such as mushrooms, and hate others, such as olives. Even among the toppings I like (or dislike), I prefer some more than others, depending on the amount.
My brother lets me take a wedge of any size from the pizza. I make two cuts from the center of the pizza to its edge and keep one of the two resulting pieces. If a cut goes through a topping, the entire topping belongs to the piece that contains the center of the topping. I am not allowed to cut exactly through the center of a topping, so each topping stays entirely on one of the pieces. I want to cut and choose the piece that is best for me.
Input
Input contains multiple test cases. The first line contains , the number of test cases, followed by test cases. The first line of each test case contains one integer , the number of toppings. It is followed by lines, each with three space-separated integers. Each line describes one topping. The first integer is my preference for the topping. The next two integers are the and coordinates of the topping's center.
Output
For each test case, output one line with the sum of the preferences of all toppings on the best piece. The best piece is the one with the maximum possible sum.
Constraints
- preference
- The point lies within the pizza, which is a circle centered at with radius . The point is never the center itself.
- Multiple toppings may share the same center.
- A set of test cases does not exceed 4MB in file size.