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

#include <bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;

int main() {
  int N;
  cin >> N;
  int cmax = INT_MIN;
  int dmax = INT_MIN;
  int cmin = INT_MAX;
  int dmin = INT_MAX;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    int c = x + y;
    int d = x - y;
    cmax = max(cmax, c);
    cmin = min(cmin, c);
    dmax = max(dmax, d);
    dmin = min(dmin, d);
  }

  cout << max(cmax - cmin, dmax - dmin) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;

long long N;

long long x[100000], y[100000];

void ran() {
  N = rand() % 20 + 2;
  for (int i = 0; i < N; i++) {
    x[i] = rand() % 100 + 1;
    y[i] = rand() % 100 + 1;
  }
}

void inp() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }
}

int gutyoku() {
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int d = abs(x[j] - x[i]) + abs(y[j] - y[i]);
      // cout<<d<<","<<i<<","<<j<<endl;
      if (d > ans) {
        ans = d;
      }
      // ans=max(ans,abs(x[j]-x[i])+abs(y[j]-y[i]));
    }
  }
  return ans;
}

int solve() {

  long long ans = 0;

  int mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxx < x[i] || (mxx == x[i] && mxy < y[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxx < x[i] || (mxx == x[i] && mxy > y[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxx > x[i] || (mxx == x[i] && mxy < y[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxx > x[i] || (mxx == x[i] && mxy > y[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxy > y[i] || (mxy == y[i] && mxx < x[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxy > y[i] || (mxy == y[i] && mxx > x[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxy < y[i] || (mxy == y[i] && mxx < x[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxy < y[i] || (mxy == y[i] && mxx > x[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxx + mxy > x[i] + y[i]) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (mxx + mxy < x[i] + y[i]) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (min(mxx, mxy) < min(x[i], y[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (min(mxx, mxy) > min(x[i], y[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (max(mxx, mxy) < max(x[i], y[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  mxx = x[0], mxy = y[0];
  for (int i = 1; i < N; i++) {
    if (max(mxx, mxy) > max(x[i], y[i])) {
      mxx = x[i];
      mxy = y[i];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
  }

  int c = 500;
  while (c--) {
    int n = rand() % N;
    mxx = x[n];
    mxy = y[n];
    for (int i = 0; i < N; i++) {
      ans = max(ans, abs(mxx - x[i]) + abs(mxy - y[i]));
    }
  }

  cout << ans << endl;
  return ans;
}

int main() {
  while (1) {
    inp();
    // int a=gutyoku();
    int b = solve();
    // cout<<b<<endl;
    break;
    /*if(a!=b){
        cout<<"NO"<<endl;
        cout<<a<<","<<b<<endl;
        cout<<N<<endl;
        for(int i=0;i<N;i++){
            cout<<x[i]<<","<<y[i]<<" ";
        }
        cout<<endl;
        break;
    }*/
  }
}