Language: C++

#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <deque>
#include <tuple>
#include <cstring>
#include <functional>
#include <queue>


using namespace std;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef pair<int, int> Pii;
using namespace std;

struct Edge {
    int cap;
    int to;
    int rev;
    Edge() {}
    Edge(int c, int t, int r) : cap(c), to(t), rev(r) {}
};

struct CostEdge : public Edge {
    int cost;
    CostEdge() : Edge() {}
    CostEdge(int c, int t, int cs, int r) :
        Edge(c, t, r), cost(cs) {
    }
};

template<class E>
class Graph {
public:
    typedef std::vector<std::vector<E> > G;
private:
    G g;
public:
    Graph(int n) : g(G(n)) {}
    void addEdge(int from, int to, int cap, int cost) {
        g[from].push_back(E(cap, to, cost, g[to].size()));
        g[to].push_back(E(0, from, -cost, g[from].size() - 1));
    }
    G &getRowGraph() {
        return g;
    }
};

template<class E>
int minCostFlow(Graph<E> &graph, int s, int t, int f, bool negative = false) {
    typedef pair<int, int> P;
    typename Graph<E>::G &g = graph.getRowGraph();
    int n = g.size();
    int res = 0;
    vector<int> h(n, 0);
    vector<int> prevv(n);
    vector<int> preve(n);
    const int inf = 10000000;
    int eps = 1e-9;
    while (f > 0) {
        priority_queue<P, vector<P>, greater<P> > que;
        vector<int> dist(n, inf);
        dist[s] = 0;
        que.push(P(0, s));
        while (!que.empty()) {
            P p = que.top(); que.pop();
            int v = p.second;
            if (dist[v] < p.first - eps) continue;
            for (int i = 0; i < (int)g[v].size(); i++) {
                E &e = g[v][i];
                if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to] + eps) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    que.push(P(dist[e.to], e.to));
                }
            }
        }
        if (dist[t] == inf) return -1;
        for (int v = 0; v < n; v++) h[v] += dist[v];
        int d = f;
        for (int v = t; v != s; v = prevv[v]) {
            d = min(d, g[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * h[t];
        for (int v = t; v != s; v = prevv[v]) {
            E &e = g[prevv[v]][preve[v]];
            e.cap -= d;
            g[v][e.rev].cap += d;
        }
        //cout << f << " " << res << endl;
        //if( fabs(res - lastRes) < 1e-5 ) return res;
        //lastRes = res;
    }
    return res;
}


struct P {
    int x, y, c, f;
};
int main() {
    int N, M, B;
    while (cin >> N >> M >> B && N) {
        vector<P> people(N);
        for (int i = 0; i < N; i++) cin >> people[i].x >> people[i].y;
        vector<P> place(M);
        for (int i = 0; i < M; i++) {
            cin >> place[i].x >> place[i].y >> place[i].c >> place[i].f;
        }
        auto f = [&](int D,int bit){
            if( D < 0 ) return (int)1e9;
            int ans = 1e9;
            int sum = 0;
            int cnt = 0;
            for (int i = 0; i < M; i++) {
                if (bit >> i & 1) {
                    sum += place[i].c;
                    cnt += place[i].f;
                }
            }
            Graph<CostEdge> _g(N + M + 2);
            auto& g = _g.getRowGraph();
            int s = g.size() - 1;
            int t = g.size() - 2;
            for (int i = 0; i < N; i++)
                _g.addEdge(s, i, 1, 0);
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    if((bit>>j&1)==0)continue;
                    int dist = max(0, abs(people[i].x - place[j].x) + abs(people[i].y - place[j].y) - D);
                    _g.addEdge(i, N + j, 1, dist);
                }
            }
            for (int i = 0; i < M; i++) {
                _g.addEdge(N + i, t, place[i].c, 0);
            }

            int res = minCostFlow(_g, s, t, N);
            if( res != -1 ) ans = min(ans,res + cnt + __builtin_popcount(bit)*D*B);
            return ans;
        };

        int ans = 1e9;

        for(int bit = 0 ; bit < (1<<M) ; bit++){
            int l = 0 , r = 2000;
            while(r - l > 2) {
                int a = (2*l+r)/3;
                int b = (l+2*r)/3;
                if( f(a,bit) > f(b,bit) ){
                    l = a;
                }else{
                    r = b;
                }
            }
            for(int i = l; i < r; i++) ans = min(ans,f(i,bit));
+
        }
        cout << ans << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:165:9: error: expected primary-expression before '}' token
  165 |         }
      |         ^