Language: C++

#include <bits/stdc++.h>

using namespace std;

#define EPS (1e-9)

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);
  }
};

typedef Point3D Vector;

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 abs(const Point3D &p)
{
  return sqrt(norm(p));
}

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));
}

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

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;
}

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

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;
}

double distanceSP(const Segment &s, const Point3D &p)
{
  return abs(p - projection(s, p));
}

bool is_intersectSS(const Sphere &c, const Segment &l)
{
  vector<Point3D> vec;
  double d = distanceSP(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;
}

struct Light {
  Point3D p;
  double b;
  Light(){}
  Light(Point3D p, double b) :
    p(p), b(b) {}
};

double get_point(const Point3D &E, const Light &T)
{
  return T.b / ((T.p.x - E.x)*(T.p.x - E.x) + (T.p.y - E.y)*(T.p.y - E.y) + (T.p.z - E.z)*(T.p.z - E.z));
}

void merge(unordered_set<int> &u, unordered_set<int> &v)
{
  for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
    u.insert(*it);
  }
}

int main()
{
  int N, M, R;
  while (cin >> N >> M >> R, N) {
    vector<Sphere> sphs(N);
    for (int i = 0; i < N; i++) {
      cin >> sphs[i].p.x >> sphs[i].p.y >> sphs[i].p.z >> sphs[i].r;
    }
    vector<Light> ligs(M);
    for (int i = 0; i < M; i++) {
      cin >> ligs[i].p.x >> ligs[i].p.y >> ligs[i].p.z >> ligs[i].b;
    }

    Point3D E;
    cin >> E.x >> E.y >> E.z;    

    unordered_set<int> st[M];
    for (int i = 0; i < M; i++) {
      Segment s(E, ligs[i].p);
      for (int j = 0; j < N; j++) {
	if (is_intersectSS(sphs[j], s)) {
	  st[i].insert(j);
	}
      }
    }

    double res = 0;
    for (int i = 0; i < (1<<M); i++) {
      unordered_set<int> used;
      double point = 0;
      for (int j = 0; j < M; j++) {
	if (!(i >> j & 1)) continue;
	point += get_point(E, ligs[j]);
	merge(used, st[j]);
      }
      if (used.size() <= R) {
	res = max(res, point);
      }
    }
    printf("%.10f\n", res);
  }
  return 0;
}

Compiler output:
a.cc: In function 'void merge(std::unordered_set<int>&, std::unordered_set<int>&)':
a.cc:124:39: error: conversion from 'std::unordered_set<int>::iterator' {aka 'std::__detail::_Insert_base<int, int, std::allocator<int>, std::__detail::_Identity, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, true, true> >::iterator'} to non-scalar type 'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} requested
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                ~~~~~~~^~
a.cc:124:46: error: no match for 'operator!=' (operand types are 'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} and 'std::unordered_set<int>::iterator' {aka 'std::__detail::_Insert_base<int, int, std::allocator<int>, std::__detail::_Identity, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, true, true> >::iterator'})
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                           ~~ ^~ ~~~~~~~
      |                                           |          |
      |                                           |          std::unordered_set<int>::iterator {aka std::__detail::_Insert_base<int, int, std::allocator<int>, std::__detail::_Identity, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, true, true> >::iterator}
      |                                           std::set<int>::iterator {aka std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator}
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181,
                 from a.cc:1:
/usr/include/c++/14/bits/regex.h:1132:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1132 |     operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1132:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
/usr/include/c++/14/bits/regex.h:1212:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1212 |     operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1212:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
/usr/include/c++/14/bits/regex.h:1305:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1305 |     operator!=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1305:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
/usr/include/c++/14/bits/regex.h:1379:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
 1379 |     operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1379:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::unordered_set<int>::iterator' {aka 'std::__detail::_Insert_base<int, int, std::allocator<int>, std::__detail::_Identity, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, true, true> >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
/usr/include/c++/14/bits/regex.h:1473:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1473 |     operator!=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1473:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
/usr/include/c++/14/bits/regex.h:1547:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)'
 1547 |     operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1547:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::unordered_set<int>::iterator' {aka 'std::__detail::_Insert_base<int, int, std::allocator<int>, std::__detail::_Identity, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, true, true> >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
/usr/include/c++/14/bits/regex.h:1647:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1647 |     operator!=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1647:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
/usr/include/c++/14/bits/regex.h:2213:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator!=(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)'
 2213 |     operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:2213:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} is not derived from 'const std::__cxx11::match_results<_BiIter, _Alloc>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1052:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1052 |     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1052:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} is not derived from 'const std::pair<_T1, _T2>'
  124 |   for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {
      |                                                       ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:455:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  455 |     operator!=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:455:5: note:   template argument deduction/substitution failed:
a.cc:124:55: note:   'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
  124 |   for (se