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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set                                                            \\
  tree<pair<ll int, ll int>, null_type, less<pair<ll int, ll int>>,            \\
       rb_tree_tag, tree_order_statistics_node_update>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main() {
  fast;
  ll int h, m, w;
  cin >> h >> w >> m;
  ll int i, x, y;
  ll int j, val = 0, ww;
  ll int mp[h + 1] = {0};
  ll int mp1[w + 1] = {0};
  // ll int mpp[h+1][w+1];
  // for(i=0;i<=h;i++)
  // {
  //   for(j=0;j<=w;j++)
  //       mpp[i][j]=0;
  //}
  vector<pair<ll int, ll int>> temp;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    mp[x]++;
    mp1[y]++;
    temp.PB(MP(x, y));
  }
  ll int mx = 0, val2, val1;
  for (i = 1; i <= h; i++) {
    mx = max(mp[i], mx);
  }
  val2 = mx;
  ll int v[h + 1] = {0};
  ll int t1 = 0, t2 = 0;
  ll int q[w + 1] = {0};
  for (i = 1; i <= h; i++) {
    if (mp[i] == mx) {
      v[i] = -1;
      t1++;
    }
  }
  mx = 0;
  for (i = 1; i <= w; i++) {
    mx = max(mp1[i], mx);
  }
  val1 = mx;
  for (i = 1; i <= w; i++) {
    if (mp1[i] == mx) {
      q[i] = -1;
      t2++;
    }
  }
  ll int cnt = 0;
  for (i = 0; i < m; i++) {
    pair<ll int, ll int> p = temp[i];
    if (v[p.F] == -1 && q[p.S] == -1)
      cnt++;
  }
  if (cnt == t1 * t2) {
    cout << val1 + val2 - 1;
  } else
    cout << val1 + val2 << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set                                                            \\
  tree<pair<ll int, ll int>, null_type, less<pair<ll int, ll int>>,            \\
       rb_tree_tag, tree_order_statistics_node_update>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main() {
  fast;
  ll int h, m, w;
  cin >> h >> w >> m;
  ll int i, x, y;
  ll int j, val = 0, ww, q;
  map<ll int, ll int> mp, mp1;
  ll int mpp[h + 1][w + 1];
  for (i = 0; i <= h; i++) {
    for (j = 0; j <= w; j++)
      mpp[i][j] = 0;
  }
  // map<pair<ll int,ll int>,ll int> mpp;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    mp[x]++;
    mp1[y]++;
    mpp[x][y] = -1;
  }
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      ww = mp[i];
      q = mp1[j];
      ll int z = ww + q;
      if (mpp[i][j] == -1)
        z--;
      val = max(z, val);
    }
  }
  cout << val << endl;
}