alexjercan/bugnet huggingface dataset:
Problem p00485 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define INF 1 << 20
typedef pair<int, int> p;
int N, M, K, a, b, l, d[3005], rd[3005];
vector<p> G[3005]; // to,cost

void dij(int s) {
  priority_queue<p, vector<p>, greater<p>> Q;
  fill(d, d + N, INF);
  d[s] = 0;
  Q.push(p(0, s));
  for (; !Q.empty();) {
    p tmp = Q.top();
    Q.pop();
    int v = tmp.second;
    if (d[v] < tmp.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      p e = G[v][i];
      if (d[e.first] > d[v] + e.second) {
        d[e.first] = d[v] + e.second;
        Q.push(p(d[e.first], e.first));
      }
    }
  }
}

int main() {
  scanf("%d%d%d", &N, &M, &K);
  for (int i = 0; i < M; i++) {
    scanf("%d%d%d", &a, &b, &l);
    a--;
    b--;
    G[a].push_back(p(b, l));
    G[b].push_back(p(a, l));
  }
  fill(rd, rd + N, INF);
  for (int i = 0; i < K; i++) {
    scanf("%d", &a);
    a--;
    dij(a);
    for (int j = 0; j < N; j++)
      rd[j] = min(rd[j], d[j]);
  }
  int res = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < G[i].size(); j++) {
      int tmp =
          (double)(abs(rd[i] - rd[G[i][j].first]) + G[i][j].second) / 2 + 0.5;
      int tmp1 = rd[G[i][j].first];
      int tmp2 = G[i][j].second - tmp;
      res = max(res, rd[i] + (rd[i] <= tmp1 ? max(tmp, tmp2) : min(tmp, tmp2)));
    }
  printf("%d\\n", res);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define INF 1 << 20
typedef pair<int, int> p;
int N, M, K, a, b, l, d[3000], rd[3000];
vector<p> G[3000]; // to,cost
vector<int> S;

void dij(int s) {
  priority_queue<p, vector<p>, greater<p>> Q;
  fill(d, d + N, INF);
  d[s] = 0;
  Q.push(p(0, s));
  for (; !Q.empty();) {
    p tmp = Q.top();
    Q.pop();
    int v = tmp.second;
    if (d[v] < tmp.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      p e = G[v][i];
      if (d[e.first] > d[v] + e.second) {
        d[e.first] = d[v] + e.second;
        Q.push(p(d[e.first], e.first));
      }
    }
  }
}

int main() {
  scanf("%d%d%d", &N, &M, &K);
  for (int i = 0; i < M; i++) {
    scanf("%d%d%d", &a, &b, &l);
    a--;
    b--;
    G[a].push_back(p(b, l));
    G[b].push_back(p(a, l));
  }
  fill(rd, rd + N, INF);
  for (int i = 0; i < K; i++) {
    scanf("%d", &a);
    a--;
    dij(a);
    for (int j = 0; j < N; j++)
      rd[j] = min(rd[j], d[j]);
  }
  int res = 0;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < G[i].size(); j++) {
      int tmp =
          (double)(abs(rd[i] - rd[G[i][j].first]) + G[i][j].second) / 2 + 0.5;
      int tmp1 = rd[G[i][j].first];
      int tmp2 = G[i][j].second - tmp;
      res = max(res, rd[i] + (rd[i] <= tmp1 ? max(tmp, tmp2) : min(tmp, tmp2)));
    }
  printf("%d\\n", res);
  return 0;
}
Problem p00485 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

struct TOWN {
  bool kaku;
  int kyo;
  vector<pair<int, int>> road;

  TOWN() : kaku(false) {}
} town[3001];

int main() {
  int n, m, k, a, b, l, ina[100000], inb[100000], inl[100000], ans = 0;
  priority_queue<pair<int, int>> pq;
  pair<int, int> p;

  scanf("%d%d%d", &n, &m, &k);

  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &l);
    town[a].road.push_back(make_pair(b, -l));
    town[b].road.push_back(make_pair(a, -l));
    ina[i] = a;
    inb[i] = b;
    inl[i] = l;
  }

  for (int i = 0; i < k; i++) {
    scanf("%d", &a);
    pq.push(make_pair(0, a));
  }

  while (!pq.empty()) {
    p = pq.top();
    pq.pop();

    if (town[p.second].kaku)
      continue;
    town[p.second].kaku = true;
    town[p.second].kyo = -p.first;

    for (int i = 0; i < town[p.second].road.size(); i++)
      pq.push(make_pair(p.first + town[p.second].road[i].second,
                        town[p.second].road[i].first));
  }

  for (int i = 0; i < m; i++) {
    int sa = abs(town[ina[i]].kyo - town[inb[i]].kyo);
    ans = max(ans, (max(inl[i] - sa, 0) + 1) / 2 +
                       max(town[ina[i]].kyo, town[inb[i]].kyo));
  }

  printf("%d\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

struct TOWN {
  bool kaku;
  int kyo;
  vector<pair<int, int>> road;

  TOWN() : kaku(false) {}
} town[3001];

int main() {
  int n, m, k, a, b, l, ina[3000], inb[3000], inl[3000], ans = 0;
  priority_queue<pair<int, int>> pq;
  pair<int, int> p;

  scanf("%d%d%d", &n, &m, &k);

  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &l);
    town[a].road.push_back(make_pair(b, -l));
    town[b].road.push_back(make_pair(a, -l));
    ina[i] = a;
    inb[i] = b;
    inl[i] = l;
  }

  for (int i = 0; i < k; i++) {
    scanf("%d", &a);
    pq.push(make_pair(0, a));
  }

  while (!pq.empty()) {
    p = pq.top();
    pq.pop();

    if (town[p.second].kaku)
      continue;
    town[p.second].kaku = true;
    town[p.second].kyo = -p.first;

    for (int i = 0; i < town[p.second].road.size(); i++)
      pq.push(make_pair(p.first + town[p.second].road[i].second,
                        town[p.second].road[i].first));
  }

  for (int i = 0; i < m; i++) {
    int sa = abs(town[ina[i]].kyo - town[inb[i]].kyo);
    ans = max(ans, (max(inl[i] - sa, 0) + 1) / 2 +
                       max(town[ina[i]].kyo, town[inb[i]].kyo));
  }

  printf("%d\\n", ans);

  return 0;
}
Problem p00485 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> PP;
int n, m, k, x, y, z;
vector<PP> v[3010];                            // cost,to
priority_queue<PP, vector<PP>, greater<PP>> Q; // cost,to
int d[3010];
int main() {
  cin >> n >> m >> k;
  rep(i, m) {
    cin >> x >> y >> z;
    x--, y--;
    v[x].push_back(make_pair(z, y));
    v[y].push_back(make_pair(z, x));
  }
  rep(i, n) d[i] = 1145141919;
  rep(u, k) {
    cin >> m;
    m--;
    while (!Q.empty())
      Q.pop();
    Q.push(make_pair(0, m));
    while (!Q.empty()) {
      x = Q.top().X, y = Q.top().Y;
      Q.pop();
      if (d[y] > x) {
        d[y] = x;
        rep(i, v[y].size()) {
          if (d[v[y][i].Y] > d[y] + v[y][i].X)
            Q.push(make_pair(d[y] + v[y][i].X, v[y][i].Y));
        }
      }
    }
  }
  // rep(i,n)cout<<d[i]<<" ";cout<<endl;
  int ans = -1;
  rep(i, n) rep(j, v[i].size()) {
    ans = max(ans, d[i] + d[v[i][j].Y] + v[i][j].X);
  }
  cout << ans / 2 + ans % 2 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, m, k;
vector<pair<int, int>> v[3010];   // cost,to
priority_queue<pair<int, int>> Q; // cost,to
int d[3010];
int main() {
  cin >> n >> m >> k;
  rep(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    v[x].push_back(make_pair(z, y));
    v[y].push_back(make_pair(z, x));
  }
  rep(i, n) d[i] = 1145141919;
  rep(u, k) {
    cin >> m;
    m--;
    while (!Q.empty())
      Q.pop();
    Q.push(make_pair(0, m));
    while (!Q.empty()) {
      int x = Q.top().X, y = Q.top().Y;
      Q.pop();
      if (d[y] > x) {
        d[y] = x;
        rep(i, v[y].size()) { Q.push(make_pair(d[y] + v[y][i].X, v[y][i].Y)); }
      }
    }
  }
  // rep(i,n)cout<<d[i]<<" ";cout<<endl;
  int ans = -1;
  rep(i, n) rep(j, v[i].size()) {
    ans = max(ans, d[i] + d[v[i][j].Y] + v[i][j].X);
  }
  cout << ans / 2 + ans % 2 << endl;
  return 0;
}
Problem p00485 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <vector>
#define INF 200000000
using namespace std;
typedef pair<int, int> P;
typedef struct {
  int a, b, c;
} edge;
vector<P> e[3000];
edge e2[100000];
int d[3000];
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int n, m, k;
  int i, j;
  scanf("%d %d %d", &n, &m, &k);
  for (i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    x--;
    y--;
    edge ed = {x, y, z};
    e[x].push_back(P(y, z));
    e[y].push_back(P(x, z));
    e2[i] = ed;
  }
  priority_queue<P> que;
  for (i = 0; i < n; i++)
    d[i] = INF;
  for (i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    d[x - 1] = 0;
    que.push(P(0, x - 1));
  }
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (i = 0; i < e[v].size(); i++) {
      if (d[e[v][i].first] > d[v] + e[v][i].second) {
        d[e[v][i].first] = d[v] + e[v][i].second;
        que.push(P(d[e[v][i].first], e[v][i].first));
      }
    }
  }
  int ans = 0;
  for (i = 0; i < m; i++) {
    int x = e2[i].a;
    int y = e2[i].b;
    int z = e2[i].c;
    ans = max(ans,
              max(d[x], max(d[y], (int)round((double)(d[x] + d[y] + z) / 2))));
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <vector>
#define INF 200000000
using namespace std;
typedef struct {
  int a, b, c;
} edge;
typedef struct {
  int to, cost;
} edge2;
typedef pair<int, int> P;
edge e[100000];
vector<edge2> ve[3000];
int d[3000];
int md[3000];
int n, m, k;
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
void solve(int s) {
  int i;
  priority_queue<P> que;
  for (i = 0; i < n; i++)
    d[i] = INF;
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (i = 0; i < ve[v].size(); i++) {
      if (d[ve[v][i].to] > d[v] + ve[v][i].cost) {
        d[ve[v][i].to] = d[v] + ve[v][i].cost;
        que.push(P(d[ve[v][i].to], ve[v][i].to));
      }
    }
  }
  for (i = 0; i < n; i++)
    md[i] = min(md[i], d[i]);
}
int main() {
  int i, j;
  scanf("%d %d %d", &n, &m, &k);
  for (i = 0; i < n; i++)
    md[i] = INF;
  for (i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    edge ed = {x - 1, y - 1, z};
    edge2 ed2 = {y - 1, z};
    edge2 ed3 = {x - 1, z};
    e[i] = ed;
    ve[x - 1].push_back(ed2);
    ve[y - 1].push_back(ed3);
  }
  for (i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    solve(x - 1);
  }
  int ans = 0;
  for (i = 0; i < m; i++) {
    int mid = (int)round((double)(md[e[i].a] + md[e[i].b] + e[i].c) / 2);
    ans = max(ans, max(mid, max(md[e[i].a], md[e[i].b])));
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p00486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)

int w, h, n, x[100002], y[100002];
int tx[100002], ty[100002];
vector<int> vx, vy;

signed main() {
  cin >> w >> h >> n;
  rep(i, n) {
    cin >> x[i] >> y[i];
    tx[i] = x[i];
    ty[i] = y[i];
  }
  sort(x, x + n);
  sort(y, y + n);
  if (n % 2) {
    vx.push_back(x[n / 2]);
    vy.push_back(y[n / 2]);
  } else {
    vx.push_back(x[n / 2 - 1]), vx.push_back(x[n / 2]);
    vy.push_back(y[n / 2 - 1]), vy.push_back(y[n / 2]);
  }
  int t = 1000000000000000, ax, ay;
  for (int sx : vx)
    for (int sy : vy) {
      int sum = 0, md = 0;
      rep(i, n) {
        int d = abs(tx[i] - sx) + abs(ty[i] - sy);
        sum += d * 2;
        md = max(md, d);
      }
      sum -= md;
      if (sum < t) {
        t = sum;
        ax = sx;
        ay = sy;
      }
    }
  cout << t << endl;
  cout << ax << " " << ay << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)

int w, h, n, x[100002], y[100002];
int tx[100002], ty[100002];
vector<int> vx, vy;

signed main() {
  cin >> w >> h >> n;
  rep(i, n) {
    cin >> x[i] >> y[i];
    tx[i] = x[i];
    ty[i] = y[i];
  }
  sort(x, x + w);
  sort(y, y + h);
  if (h % 2)
    vx.push_back(x[h / 2]);
  else
    vx.push_back(x[h / 2]), vx.push_back(x[h / 2 + 1]);
  if (w % 2)
    vy.push_back(y[w / 2]);
  else
    vy.push_back(y[w / 2]), vy.push_back(y[w / 2 + 1]);
  int t = 1000000000000000, ax, ay;
  for (int sx : vx)
    for (int sy : vy) {
      int sum = 0, md = 0;
      rep(i, n) {
        int d = abs(tx[i] - sx) + abs(ty[i] - sy);
        sum += d * 2;
        md = max(md, d);
      }
      if (sum - md < t) {
        t = sum - md;
        ax = sx;
        ay = sy;
      }
    }
  cout << t << endl;
  cout << ax << " " << ay << endl;
}
Problem p00486 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int ox[100000];
int oy[100000];
int x[100000];
int y[100000];
int n;
long long calc(int a, int b) {
  int md = 0, i;
  long long ans = 0;
  for (i = 0; i < n; i++) {
    int d = abs(ox[i] - a) + abs(oy[i] - b);
    md = max(md, d);
    ans += (long long)d * 2;
  }
  return ans - (long long)md;
}
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int w, h, i, j;
  scanf("%d %d", &w, &h);
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &ox[i], &oy[i]);
    x[i] = ox[i];
    y[i] = oy[i];
  }
  sort(x, x + n);
  sort(y, y + n);
  long long ans = 1000000000000000000LL;
  int ax[2];
  int ay[2];
  ax[0] = x[n / 2];
  ay[0] = y[n / 2];
  int nx, ny;
  if (n % 2 == 0) {
    ax[1] = x[n / 2 - 1];
    ay[1] = y[n / 2 - 1];
    for (i = 1; i >= 0; i--)
      for (j = 1; j >= 0; j--) {
        if (ans > calc(ax[i], ay[j])) {
          ans = calc(ax[i], ay[j]);
          nx = ax[i];
          ny = ay[j];
        }
      }
  } else {
    ans = calc(ax[0], ay[0]);
    nx = ax[0];
    ny = ay[0];
  }
  printf("%lld\\n", ans);
  printf("%d %d\\n", nx, ny);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int ox[100000];
int oy[100000];
int x[100000];
int y[100000];
int n;
long long calc(int a, int b) {
  int md = 0, i;
  long long ans = 0;
  for (i = 0; i < n; i++) {
    int d = abs(ox[i] - a) + abs(oy[i] - b);
    md = max(md, d);
    ans += (long long)d * 2;
  }
  return ans - (long long)md;
}
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int w, h, i, j;
  scanf("%d %d", &w, &h);
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &ox[i], &oy[i]);
    x[i] = ox[i];
    y[i] = oy[i];
  }
  sort(x, x + n);
  sort(y, y + n);
  long long ans = 1000000000000000000LL;
  int ax[2];
  int ay[2];
  ax[0] = x[n / 2];
  ay[0] = y[n / 2];
  int nx, ny;
  if (n % 2 == 0) {
    ax[1] = x[n / 2 - 1];
    ay[1] = y[n / 2 - 1];
    for (i = 1; i >= 0; i++)
      for (j = 1; j >= 0; j++) {
        if (ans > calc(ax[i], ay[j])) {
          ans = calc(ax[i], ay[j]);
          nx = ax[i];
          ny = ay[j];
        }
      }
  } else {
    ans = calc(ax[0], ay[0]);
    nx = ax[0];
    ny = ay[0];
  }
  printf("%lld\\n", ans);
  printf("%d %d\\n", nx, ny);
  return 0;
}
Problem p00486 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int points[100005][2], xs[100005], ys[100005], n, w, h;
  long long int sums = 0;
  scanf("%d%d%d", &w, &h, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", xs + i, ys + i);
    points[i][0] = xs[i];
    points[i][1] = ys[i];
  }
  sort(xs, xs + n);
  sort(ys, ys + n);
  long long int ans = -1;
  int ansx, ansy;
  int up = min((n / 2) + 2, n - 1);
  int down = max(0, (n / 2) - 2);

  for (int i = down; i <= up; i++) {
    for (int j = down; j <= up; j++) {
      long long int res = 0, far = 0, d;
      for (int k = 0; k < n; k++) {
        d = abs(points[k][0] - xs[i]) + abs(points[k][1] - ys[j]);
        far = max(far, d);
        res += d * 2;
      }
      if (ans == -1 || ans > res - far) {
        ans = res - far;
        ansx = xs[i];
        ansy = ys[j];
      }
    }
  }
  printf("%lld\\n", ans);
  printf("%d %d\\n", ansx, ansy);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int points[100005][2], xs[100005], ys[100005], n, w, h;
  scanf("%d%d%d", &w, &h, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", xs + i, ys + i);
    points[i][0] = xs[i];
    points[i][1] = ys[i];
  }
  sort(xs, xs + w);
  sort(ys, ys + h);
  long long int ans = -1;
  int ansx, ansy;
  int wup = min((w / 2) + 3, w - 1);
  int wdown = max(0, (w / 2) - 3);
  int hup = min((h / 2) + 3, h - 1);
  int hdown = max(0, (h / 2) - 3);

  for (int i = wdown; i <= wup; i++) {
    for (int j = hdown; j <= hup; j++) {
      long long int res = 0;
      int far = 0;
      for (int k = 0; k < n; k++) {
        far = max(far, abs(points[k][0] - xs[i]) + abs(points[k][1] - ys[j]));
        res += (abs(points[k][0] - xs[i]) + abs(points[k][1] - ys[j])) * 2;
      }
      if (ans == -1 || ans > res - far) {
        ans = res - far;
        ansx = xs[i];
        ansy = ys[j];
      }
    }
  }
  printf("%lld\\n", ans);
  printf("%d %d\\n", ansx, ansy);
  return 0;
}
Problem p00486 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int N, x[2][100009], p[100009], z[2][100009];
long long v[2][100009];
int main() {
  scanf("%*d%*d%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d%d", &x[0][i], &x[1][i]);
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++)
      v[i][j] = 1LL << 60, p[j] = j;
    sort(p, p + N, [&](int j, int k) { return x[i][j] < x[i][k]; });
    for (int j = (N - 1) / 2; j <= N / 2; j++) {
      long long sum = 0;
      for (int k = 0; k < N; k++)
        sum += abs(x[i][p[j]] - x[i][k]) * 2;
      for (int k = 0; k < N; k++) {
        long long cost = sum - abs(x[i][p[j]] - x[i][k]);
        if (v[i][k] > cost)
          v[i][k] = cost, z[i][k] = x[i][p[j]];
      }
    }
  }
  long long ret = 1LL << 60;
  int lp = -1;
  for (int i = 0; i < N; i++) {
    long long c = v[0][i] + v[1][i];
    if (ret > c || (ret == c && (z[0][lp] > z[0][i] ||
                                 (z[0][lp] == z[0][i] && z[1][lp] > z[1][i]))))
      ret = c, lp = i;
  }
  printf("%lld\\n%d %d\\n", ret, z[0][lp], z[1][lp]);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int inf = 1012345678;
int W, H, N, x[100009], y[100009], sx[100009], sy[100009];
int main() {
  scanf("%d%d%d", &W, &H, &N);
  assert(N <= 1000);
  for (int i = 0; i < N; i++)
    scanf("%d%d", &x[i], &y[i]), sx[i] = x[i], sy[i] = y[i];
  long long ret = 1LL << 60;
  int px = 0, py = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      long long sum = 0;
      int m = 0;
      for (int k = 0; k < N; k++) {
        int dist = abs(x[i] - x[k]) + abs(y[j] - y[k]);
        sum += dist;
        m = max(m, dist);
      }
      sum = sum * 2 - m;
      if (ret > sum)
        ret = sum, px = inf, py = inf;
      if (ret == sum) {
        if (px > x[i] || (px == x[i] && py > y[j])) {
          px = x[i];
          py = y[j];
        }
      }
    }
  }
  printf("%lld\\n", ret);
  printf("%d %d\\n", px, py);
  return 0;
}
Problem p00486 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) begin(c), end(c)

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
signed main() {
  int W, H, N;
  cin >> W >> H >> N;
  V ws(N), hs(N);
  vector<P> v(N);
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    ws[i] = x;
    hs[i] = y;
    v[i] = P(x, y);
  }
  sort(all(ws));
  sort(all(hs));

  vector<VV> dists(3, VV(3, V(N)));
  rep(i, N) rep(j, 3) rep(k, 3) {
    dists[j][k][i] = abs(v[i].first - ws[N / 2 + j - 1]) +
                     abs(v[i].second - hs[N / 2 + k - 1]);
  }
  rep(i, 3) rep(j, 3) sort(all(dists[i][j]));

  int ans = 1ll << 62;
  int xpos = 0, ypos = 0;
  rep(i, 3) rep(j, 3) {
    int sum = accumulate(all(dists[i][j]), 0ll) * 2 - dists[i][j].back();
    if (sum < ans) {
      xpos = ws[N / 2 + i - 1];
      ypos = hs[N / 2 + j - 1];
      ans = sum;
    }
  }
  cout << ans << endl;
  cout << xpos << " " << ypos << endl;
}

Error: -11

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, x, ...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__, REP1, REP2, REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template <typename T> bool maxup(T &a, const T &&b) {
  if (a < b) {
    a = b;
    return true;
  };
}
template <typename T> bool maxup(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  };
}
template <typename T> bool minup(T &a, const T &&b) {
  if (a > b) {
    a = b;
    return true;
  };
}
template <typename T> bool minup(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  };
}

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template <typename T> inline void input(vector<T> &v) {
  for (auto &x : v)
    cin >> x;
}

signed main() {
  int W, H, N;
  cin >> W >> H >> N;
  V ws(N), hs(N);
  vector<P> v(N);
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    ws[i] = x;
    hs[i] = y;
    v[i] = P(x, y);
  }
  sort(all(ws));
  sort(all(hs));

  vector<VV> dists(3, VV(3, V(N)));
  rep(i, N) rep(j, -1, 2) rep(k, -1, 2) {
    dists[j][k][i] =
        abs(v[i].first - ws[N / 2 + j]) + abs(v[i].second - hs[N / 2 + k]);
  }
  rep(i, 9) sort(all(dists[i]));

  int ans = 1ll << 62;
  int xpos = 0, ypos = 0;
  rep(i, 3) rep(j, 3) {
    int sum = accumulate(all(dists[i][j]), 0ll) * 2 - dists[i][j].back();
    if (sum < ans) {
      xpos = ws[N / 2 + i];
      ypos = hs[N / 2 + j];
      ans = sum;
    }
  }
  cout << ans << endl;
  cout << xpos << " " << ypos << endl;

  // system("pause");
}