This page is still under construction.

Parts of this page are still being built. What you see may change.

Let There Be Light

Time limit5sMemory limit128 MB

Summary
Given up to 2000 balloons blocking up to 15 point lights from a target point, choose at most R balloons to remove to maximize total illumination, computed via geometric occlusion and a min-cut/greedy set-cover style optimization over light-blocking sets, printed as an exact fraction.
Level

Medium7 of 10

Topics
Geometry, Bit manipulation, Combinatorics, Brute force
Solved
No attempts yet

Problem

Suppose there are some light sources and many spherical balloons. Every light source is small enough to be modeled as a point light source, and it emits light in all directions. The surfaces of the balloons absorb light and do not reflect it. Surprisingly, in this world balloons may overlap.

You want the total illumination intensity at an objective point to be as high as possible. To achieve this, some of the balloons that obstruct light can be removed. Because of removal costs, however, there is a limit on the number of balloons that may be removed. You would like to remove an appropriate set of balloons so as to maximize the illumination intensity at the objective point.

Input

The input is a sequence of datasets. Each dataset is formatted as follows.

N M R
S1x S1y S1z S1r
...
SNx SNy SNz SNr
T1x T1y T1z T1b
...
TMx TMy TMz TMb
Ex Ey Ez

The first line of a dataset contains three positive integers NN, MM and RR, separated by a single space. NN is the number of balloons and does not exceed 20002000. MM is the number of light sources and does not exceed 1515. RR is the number of balloons that may be removed, which does not exceed NN.

Each of the following NN lines contains four integers separated by a single space. (Six,Siy,Siz)(S_{ix}, S_{iy}, S_{iz}) is the center of the ii-th balloon and SirS_{ir} is its radius.

Each of the following MM lines contains four integers separated by a single space. (Tjx,Tjy,Tjz)(T_{jx}, T_{jy}, T_{jz}) is the position of the jj-th light source and TjbT_{jb} is its brightness.

The last line of a dataset contains three integers separated by a single space. (Ex,Ey,Ez)(E_x, E_y, E_z) is the position of the objective point.

SixS_{ix}, SiyS_{iy}, SizS_{iz}, TjxT_{jx}, TjyT_{jy}, TjzT_{jz}, ExE_x, EyE_y and EzE_z are greater than −500-500 and less than 500500. SirS_{ir} is greater than 00 and less than 500500. TjbT_{jb} is greater than 00 and less than 8000080000.

At the objective point, the intensity of the light from the jj-th light source, if no balloon interrupts it, is inversely proportional to the square of the distance, namely

Tjb(Tjx−Ex)2+(Tjy−Ey)2+(Tjz−Ez)2\frac{T_{jb}}{(T_{jx}-E_x)^2 + (T_{jy}-E_y)^2 + (T_{jz}-E_z)^2}

The total illumination intensity is the sum of these contributions over the light sources that reach the objective point.

You may assume the following.

  • The distance between the objective point and any light source is at least 11.
  • For every ii and jj, even if SirS_{ir} changes by ε\varepsilon (with ∣ε∣<0.01|\varepsilon| < 0.01), whether the ii-th balloon hides the jj-th light source or not does not change.

The end of the input is indicated by a line of three zeros.

Output

For each dataset, output on its own line the maximum possible total illumination intensity at the objective point after removing at most RR balloons.

Because every coordinate, radius, and brightness is an integer, each light source that reaches the objective point contributes an intensity of the form Tjb/DjT_{jb}/D_j with an integer DjD_j, so the maximum total intensity is always a rational number. Print it as an exact reduced fraction p/q, where q is a positive integer, p is a non-negative integer, and gcd⁡(p,q)=1\gcd(p, q) = 1. When the maximum intensity is 00, print 0/1.

Examples1

  1. Example 1

    Input
    12 5 4
    0 10 0 1
    1 5 0 2
    1 4 0 2
    0 0 0 2
    10 0 0 1
    3 -1 0 2
    5 -1 0 2
    10 10 0 15
    0 -10 0 1
    10 -10 0 1
    -10 -10 0 1
    10 10 0 1
    0 10 0 240
    10 0 0 200
    10 -2 0 52
    -10 0 0 100
    1 1 0 2
    0 0 0
    12 5 4
    0 10 0 1
    1 5 0 2
    1 4 0 2
    0 0 0 2
    10 0 0 1
    3 -1 0 2
    5 -1 0 2
    10 10 0 15
    0 -10 0 1
    10 -10 0 1
    -10 -10 0 1
    10 10 0 1
    0 10 0 260
    10 0 0 200
    10 -2 0 52
    -10 0 0 100
    1 1 0 2
    0 0 0
    5 1 3
    1 2 0 2
    -1 8 -1 8
    -2 -3 5 6
    -2 1 3 3
    -4 2 3 5
    1 1 2 7
    0 0 0
    5 1 2
    1 2 0 2
    -1 8 -1 8
    -2 -3 5 6
    -2 1 3 3
    -4 2 3 5
    1 1 2 7
    0 0 0
    0 0 0
    
    Expected output
    7/2
    18/5
    7/6
    0/1