Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set<ll>
#define vi vector<ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map<ll, ll>
#define vpi vector<pair<ll, ll>>
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define mem0(a) memset(a, 0, sizeof(a))
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define ld long double
#define rall(a) (a).rbegin(), (a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

ll power(ll b, ll e, ll m) {
  if (b == 0)
    return 0;
  if (e == 0)
    return 1;
  if (e & 1)
    return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
ll power(ll b, ll e) {
  if (b == 0)
    return 0;
  if (e == 0)
    return 1;
  if (e & 1)
    return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
bool isPowerOfTwo(ll x) {
  // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2
  // or not
  return (x && !(x & (x - 1)));
}

ll pts[1000005][2] = {0};

ll mnht(ll pt[1000005][2], int kth, int idx, int d) {
  ll dist = 0;

  for (int i = 0; i < d; i++) {
    dist += abs(pt[kth][i] - pt[idx][i]);
  }

  return dist;
}
ll max_cmb(ll cmbn[2], ll pt[1000005][2], int n, int d) {
  ll pk = 0;
  ll idx = 0;

  for (int i = 0; i < n; i++) {
    ll val = 0;

    for (int j = 0; j < d; j++) {
      val += (1 - 2 * cmbn[j]) * pt[i][j];
    }

    if (val > pk) {
      pk = val;
      idx = i;
    }
  }

  return idx;
}

void solve() {
  ll n, d;
  cin >> n;
  d = 2;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++)
      cin >> pts[i][j];
  }

  ll pk[2 << d];

  for (int j = 0; j < 1 << (d); j++) {
    ll cmbn[2] = {0};
    for (int dig = 0; dig < d; dig++) {
      if (j & 1 << dig)
        cmbn[dig] = 1;
      // cout<<cmbn[dig]<<" ";
    }
    // cout<<endl;
    pk[j] = max_cmb(cmbn, pts, n, d);
  }

  ll maxd = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 1 << (d); j++)
      maxd = max(maxd, mnht(pts, i, pk[j], d));
  }

  cout << maxd << endl;
}

int main() {
  ll tt = 1;
  // cin>>tt;
  while (tt--) {
    solve();
    cout << "\\n";
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set<ll>
#define vi vector<ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map<ll, ll>
#define vpi vector<pair<ll, ll>>
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define mem0(a) memset(a, 0, sizeof(a))
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define ld long double
#define rall(a) (a).rbegin(), (a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

ll power(ll b, ll e, ll m) {
  if (b == 0)
    return 0;
  if (e == 0)
    return 1;
  if (e & 1)
    return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
ll power(ll b, ll e) {
  if (b == 0)
    return 0;
  if (e == 0)
    return 1;
  if (e & 1)
    return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
bool isPowerOfTwo(ll x) {
  // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2
  // or not
  return (x && !(x & (x - 1)));
}

ll pts[100005][2] = {0};

ll mnht(ll pt[100005][2], int kth, int idx, int d) {
  ll dist = 0;

  for (int i = 0; i < d; i++) {
    dist += abs(pt[kth][i] - pt[idx][i]);
  }

  return dist;
}
ll max_cmb(ll cmbn[2], ll pt[100005][2], int n, int d) {
  ll pk = 0;
  ll idx = 0;

  for (int i = 0; i < n; i++) {
    ll val = 0;

    for (int j = 0; j < d; j++) {
      val += (1 - 2 * cmbn[j]) * pt[i][j];
    }

    if (val > pk) {
      pk = val;
      idx = i;
    }
  }

  return idx;
}

void solve() {
  ll n, d;
  cin >> n;
  d = 2;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++)
      cin >> pts[i][j];
  }

  ll pk[2 << d];

  for (int j = 0; j < 1 << (d); j++) {
    ll cmbn[2] = {0};
    for (int dig = 0; dig < d; dig++) {
      if (j & 1 << dig)
        cmbn[dig] = 1;
      // cout<<cmbn[dig]<<" ";
    }
    // cout<<endl;
    pk[j] = max_cmb(cmbn, pts, n, d);
  }

  ll maxd = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 1 << (d); j++)
      maxd = max(maxd, mnht(pts, i, pk[j], d));
  }

  cout << maxd << endl;
}

int main() {
  ll tt = 1;
  // cin>>tt;
  while (tt--) {
    solve();
    cout << "\\n";
  }
}