Under construction

Still being built. Things may change

Love for Pizza

Time limit2sMemory limit1024 MB

Summary
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 TT, the number of test cases, followed by TT test cases. The first line of each test case contains one integer NN, the number of toppings. It is followed by NN 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 xx and yy 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

  • 1≤T≤251 \le T \le 25
  • 1≤N≤1051 \le N \le 10^5
  • −105≤-10^5 \le preference ≤105\le 10^5
  • The point (x,y)(x, y) lies within the pizza, which is a circle centered at (0,0)(0, 0) with radius 10910^9. 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.

Examples1

  1. Example 1

    Input
    3
    2
    -100 28335 972
    200 16646 1307
    3
    7265 341 160
    -1000 17646 24060
    2735 26741 7225
    4
    -8609 7286 1522
    9243 30219 184
    7255 19082 16933
    5317 6845 0
    
    Expected output
    200
    10000
    21815