Language: C++

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8
#define INF 2000000

struct point{
	double x,y,z,r;
	point(double _x, double _y, double _z, double _r):x(_x),y(_y),z(_z),r(_r){};
	point():x(0.0),y(0.0),z(0.0),r(0.0){};
};

inline point add(point &p1, point &p2){
	return point(p1.x+p2.x, p1.y+p2.y, p1.z+p2.z, 0.0);
}
inline point sub(point &p1, point &p2){
	return point(p1.x-p2.x, p1.y-p2.y, p1.z-p2.z, 0.0);
}
inline double dot(point &p1, point &p2){
	return p1.x*p2.x+p1.y*p2.y+p1.z*p2.z;
}
inline point mult(point &p, double k){
	return point(p.x*k,p.y*k,p.z*k,0.0);
}
inline double dist(point &p1, point &p2){
	return sqrt(pow(p1.x-p2.x, 2.0)+pow(p1.y-p2.y, 2.0)+pow(p1.z-p2.z, 2.0));
}

point lp[2222];
point ls[22];
int iss[2222];
double lum[22];

bool intersect(point a, point b, point c){//線分abに点cを中心とする風船がかかわるかどうか
	//1(両方内側にある)
	if(dist(a,c)<c.r-EPS&&dist(b,c)<c.r-EPS)return false;
	//2(片方が内側、片方が外側にある)
	if((dist(a,c)-c.r)*(dist(b,c)-c.r)<-EPS)return true;
	//3(両方が外側にある)
	point ab=sub(a,b);
	point ac=sub(a,c);
	double t=dot(ab,ac)/dot(ab,ab);
	if(EPS<t && t<1.0-EPS){
		point Q=add(a,mult(ab, -t));
		if(dist(Q,c)<c.r-EPS)return true;
		else return false;
	}else return false;
}

int main(){
	while(1){
		double ans=0.0;
		int n,m,r;
		int tx,ty,tz,tr;
		point e;
		cin>>n>>m>>r;
		if(n==0)return 0;
		memset(iss,0,sizeof(iss));
		REP(i,n){
			scanf("%d%d%d%d",&tx,&ty,&tz,&tr);
			lp[i]=point(tx,ty,tz,tr);
		}
		REP(i,m){
			scanf("%d%d%d%d",&tx,&ty,&tz,&tr);
			ls[i]=point(tx,ty,tz,tr);
		}
		REP(i,1){
			scanf("%d%d%d",&tx,&ty,&tz);
			e=point(tx,ty,tz,0.0);
		}
		REP(i,m)lum[i]=ls[i].r/pow(dist(ls[i],e),2.0);
		REP(i,n)REP(j,m)if(intersect(ls[j], e, lp[i]))iss[i]|=1<<j;
		REP(i,1<<m){
			int cost=0;
			double lu=0;
			REP(j,n)if(iss[j]&i)cost++;
			if(cost>r)continue;
			REP(j,m)if(i&(1<<j))lu+=lum[j];
			ans=max(ans,lu);
		}
		printf("%.5f\n", ans);
	}
}

Compiler output:
a.cc: In function 'bool intersect(point, point, point)':
a.cc:107:35: error: cannot bind non-const lvalue reference of type 'point&' to an rvalue of type 'point'
  107 |                 point Q=add(a,mult(ab, -t));
      |                               ~~~~^~~~~~~~
a.cc:76:36: note:   initializing argument 2 of 'point add(point&, point&)'
   76 | inline point add(point &p1, point &p2){
      |                             ~~~~~~~^~