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

#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define Speed_UP                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#warning Remeber to change t
using namespace std;
typedef long long ll;
inline void setIO(string name = "") {
#ifndef ONLINE_JUDGE
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
#endif
}
const ll mx = 1e5;
int main() {
  Speed_UP ll t;
  t = 1;
  while (t--) {
    ll h, w, m;
    cin >> h >> w >> m;

    map<pair<ll, ll>, ll> arr;
    ll rows[h + 1], col[w + 1];
    fill(rows, rows + h + 1, 0);
    fill(col, col + w + 1, 0);
    for (int i = 0; i < m; i++) {
      ll x, y;
      cin >> x >> y;
      arr[{x, y}] = 1;
      rows[x]++;
      col[y]++;
      // cout<<col[y]<<" "<<y<<" \\n";
    }
    // for(int i=1;i<=h;i++)
    // cout<<rows[i]<<" ";
    // cout<<"\\n";
    // for(int i=1;i<=w;i++)
    // cout<<col[i]<<" ";

    pair<ll, ll> candr[h], candc[w];
    for (int i = 1; i <= h; i++) {
      candr[i - 1] = {rows[i], i};
    }
    for (int i = 1; i <= w; i++) {
      candc[i - 1] = {col[i], i};
    }
    sort(candr, candr + h);
    sort(candc, candc + w);
    // for(auto u:candr)
    // cout<<u.ff<<" ";
    ll ans = 0;
    for (int i = 0; i < h; i++) {
      ll val =
          candc[w - 1].ff + candr[i].ff - arr[{candr[i].ss, candc[w - 1].ss}];
      if (val > ans) {
        ans = val;
      }
    }
    for (int i = 0; i < w; i++) {
      ll val =
          candr[h - 1].ff + candc[i].ff - arr[{candr[h - 1].ss, candc[i].ss}];
      // cout<<val<<" "<<candr[h-1].ff<<" ";
      if (val > ans) {
        ans = val;
      }
    }
    cout << ans;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define Speed_UP                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#warning Remeber to change t
using namespace std;
typedef long long ll;
inline void setIO(string name = "") {
#ifndef ONLINE_JUDGE
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
#endif
}

int main() {
  Speed_UP ll t;
  t = 1;
  while (t--) {
    ll h, w, m;
    cin >> h >> w >> m;
    ll arr[h + 1][w + 1];
    fill(arr[0], arr[0] + (h + 1) * (w + 1), 0);
    ll rows[h + 1], col[w + 1];
    fill(rows, rows + h + 1, 0);
    fill(col, col + w + 1, 0);
    for (int i = 0; i < m; i++) {
      ll x, y;
      cin >> x >> y;
      arr[x][y] = 1;
      rows[x]++;
      col[y]++;
      // cout<<col[y]<<" "<<y<<" \\n";
    }
    // for(int i=1;i<=h;i++)
    // cout<<rows[i]<<" ";
    // cout<<"\\n";
    // for(int i=1;i<=w;i++)
    // cout<<col[i]<<" ";

    pair<ll, ll> candr[h], candc[w];
    for (int i = 1; i <= h; i++) {
      candr[i - 1] = {rows[i], i};
    }
    for (int i = 1; i <= w; i++) {
      candc[i - 1] = {col[i], i};
    }
    sort(candr, candr + h);
    sort(candc, candc + w);
    // for(auto u:candr)
    // cout<<u.ff<<" ";
    ll ans = 0;
    for (int i = 0; i < h; i++) {
      ll val =
          candc[w - 1].ff + candr[i].ff - arr[candr[i].ss][candc[w - 1].ss];
      if (val > ans) {
        ans = val;
      }
    }
    for (int i = 0; i < w; i++) {
      ll val =
          candr[h - 1].ff + candc[i].ff - arr[candr[h - 1].ss][candc[i].ss];
      // cout<<val<<" "<<candr[h-1].ff<<" ";
      if (val > ans) {
        ans = val;
      }
    }
    cout << ans;
  }
}