Language: C++

#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
constexpr double EPS = 1e-10;
constexpr double INF = 1LL << 55;
constexpr double PI = acos(-1);
#define equals(a, b) (fabs(a - b) < EPS)
#define lt(a, b) (a - b < -EPS)
#define le(a, b) (lt(a, b) || equals(a, b))
struct Point3D {
    double x, y, z;
    Point3D(){}
    Point3D(double x, double y, double z) : x{x}, y{y}, z{z} {}
  
    Point3D operator + (const Point3D& p) const{
        return Point3D(x + p.x, y + p.y, z + p.z);
    }
    
    Point3D operator - (const Point3D& p) const{
        return Point3D(x - p.x, y - p.y, z - p.z);
    }
    
    Point3D operator * (double k) const{
        return Point3D(x * k, y * k, z * k);
    }
    
    Point3D operator / (double k) const{
        return Point3D(x / k, y / k, z / k);
    }
};

double dot(const Point3D& a, const Point3D& b){
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

double norm(const Point3D& p){
    return dot(p, p);
}

double norm(const Point3D& a, const Point3D& b){
    return (a.x - b.x) * (a.x - b.x) +
           (a.y - b.y) * (a.y - b.y) +
           (a.z - b.z) * (a.z - b.z);
}

double abs(const Point3D& p){
    return sqrt(norm(p));
}

double dist(const Point3D& a, const Point3D& b){
    return abs(a - b);
}

double cross(const Point3D& a, const Point3D& b){
    return abs(Point3D(a.y * b.z - a.z * b.y,
                       a.z * b.x - a.x * b.z,
                       a.x * b.y - a.y * b.x));
}

Point3D cross_vec(const Point3D& a, const Point3D& b){
    return Point3D(a.y * b.z - a.z * b.y,
                   a.z * b.x - a.x * b.z,
                   a.x * b.y - a.y * b.x);
}

double distance_PP(const Point3D& a, const Point3D& b){
    return abs(a - b);
}

istream& operator >> (istream& is, Point3D& p){
    return is >> p.x >> p.y >> p.z;
}

struct Segment {
    Point3D s, t;
    Segment() {}
    Segment(Point3D s, Point3D t) : s{s}, t{t} {}
};

struct Sphere {
    Point3D p;
    double r;
    Sphere(){}
    Sphere(Point3D p, double r) : p(p), r(r) {}
};

using Line =  Segment;

Point3D proj(const Line &l, const Point3D &p){
    Point3D b = l.t - l.s;
    double t = dot(p - l.s, b) / norm(b);
    return l.s + b * t;
}

Point3D refl(const Line& l, const Point3D& p){    
    return p + (proj(l, p) - p) * 2.0;
}

double distance_LP(const Line& l, const Point3D& p){
    return abs(p - proj(l, p));
}

double distance_LL(const Line& a, const Line& b)
{
    Point3D v = cross_vec(a.t - a.s, b.t - b.s);
    Point3D p = a.s - b.s;
    if (abs(v) < EPS) return distance_LP(a, b.s);
    return abs(dot(v, p)) / abs(v);
}
double distance_SP(const Segment& s, const Point3D& p)
{
    double a = dot(s.t - s.s, s.t - s.s);
    double b = dot(s.t - s.s, s.s - p);
    double c = dot(s.s - p, s.s - p);
    double t = -b / a;
    if (t < 0) return abs(s.s - p);
    if (t > 1) return abs(s.t - p);
    return a * t * t + 2 * b * t + c;
}

typedef Point3D Vector;
  
int ccw(const Point3D &p0, const Point3D &p1, const Point3D &p2)
{
    Vector a = p1 - p0, b = p2 - p0;
    if (abs(cross(a, b)) > EPS) return +1;
    if (abs(cross(a, b)) < -EPS) return -1;
    if (dot(a, b) < -EPS) return +2;
    if (norm(a) < norm(b)) return -2;
    return +0;
}
Point3D projection(const Segment &s, const Point3D &p)
{
    Point3D b = s.t - s.s;
    double t = dot(p - s.s, b) / norm(b);
    return s.s + b * t;
}
bool is_intersectSS(const Segment &l,const Sphere &c){
    vector<Point3D> vec;
    double d = distance_SP(l, c.p);
    if (d < c.r) {
        Point3D p = projection(l, c.p);
        Point3D v = (l.t - l.s) / abs(l.t - l.s);
        d = sqrt(c.r * c.r - d * d);
        vec.push_back(p - v * d);
        vec.push_back(p + v * d);
        for (int i = 0; i < (int)vec.size(); i++) {
            if (ccw(l.s, l.t, vec[i]) == 0) {
                return true;
            }
        }
    }
    return false;
}
double x,y,z,r[2001],po[15],ans;
int n,m,p,o=0;
Point3D X;
vector<Point3D>v,c;
vector<int>t[15];
bool used[15];
void calc(){o++;
  double score=0;
  set<int>res;
  r(i,m)if(used[i]){
    score+=po[i]/((c[i].x-X.x)*(c[i].x-X.x)+(c[i].y-X.y)*(c[i].y-X.y)+(c[i].z-X.z)*(c[i].z-X.z));
    r(j,t[i].size())res.insert(t[i][j]);
  }
  if(res.size()<=p)ans=max(ans,score);
}
void dfs(int d){
  if(d==m)calc();
  else{
    used[d]=0;
    dfs(d+1);
    used[d]=1;
    dfs(d+1);
  }
}
int main(){
  while(cin>>n>>m>>p,n){
    v.clear();
    c.clear();
    r(i,n){
      cin>>x>>y>>z>>r[i];
      v.push_back(Point3D(x,y,z));
    }
    r(i,m){
      cin>>x>>y>>z>>po[i];
      c.push_back(Point3D(x,y,z));
    }
    cin>>x>>y>>z;
    X=Point3D(x,y,z);
    r(i,m)r(j,n)if(is_intersectSS(Segment(c[i],X),Sphere(v[j],r[j])))t[i].push_back(j);
    ans=0;
    dfs(0);
    printf("%.9f\n",ans);
  }
}

Compiler output:
a.cc:84:44: error: macro "r" requires 2 arguments, but only 1 given
   84 |     Sphere(Point3D p, double r) : p(p), r(r) {}
      |                                            ^
a.cc:3:9: note: macro "r" defined here
    3 | #define r(i,n) for(int i=0;i<n;i++)
      |         ^
a.cc: In constructor 'Sphere::Sphere(Point3D, double)':
a.cc:85:1: error: expected '{' at end of input
   85 | };
      | ^