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


// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define endl '\\n'
#define pb push_back
#define int long long
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define fill(a, b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i, x, y) for (int i = (int)x; i < y; i++)
#define px(a)                                                                  \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << '\\n';
#define pxy(a, n) rep(i, 0, n){px(a[i])};
/*_________________________________________________________*/

const long long MOD = 1e9 + 7, N = 1e5 + 5;
int solve() {
  int n, ans = 0;
  cin >> n;
  int x[n], y[n];
  int a[] = {INT_MIN, INT_MAX, INT_MIN, INT_MAX};
  rep(i, 0, n) {
    int xx, yy;
    cin >> xx >> yy;
    x[i] = xx - yy;
    y[i] = xx + yy;
    a[0] = max(a[0], x[i]);
    a[1] = min(a[1], x[i]);
    a[2] = max(a[2], y[i]);
    a[3] = min(a[3], y[i]);
  }
  ans = max(abs(a[0] - a[1]), abs(a[2] - a[3]));
  return ans;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    cout << solve() << endl;
}

Error: 0

Fixed submission:


// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define endl '\\n'
#define pb push_back
#define int long long
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define fill(a, b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i, x, y) for (int i = (int)x; i < y; i++)
#define px(a)                                                                  \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << '\\n';
#define pxy(a, n) rep(i, 0, n){px(a[i])};
/*_________________________________________________________*/

const long long MOD = 1e9 + 7, N = 1e5 + 5;
int solve() {
  int n, ans = 0;
  cin >> n;
  int x[n], y[n];
  rep(i, 0, n) {
    int xx, yy;
    cin >> xx >> yy;
    x[i] = xx - yy;
    y[i] = xx + yy;
  }
  // rep(i,0,n) cout<<x[i]<<" "<<y[i]<<endl;
  ans = max(*max_element(x, x + n) - *min_element(x, x + n),
            *max_element(y, y + n) - *min_element(y, y + n));
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    cout << solve() << endl;
}