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

#include <bits/stdc++.h>
using namespace std;
int ara[300010];
int bra[300010];
int main() {
  int h, w, n, k, l;
  int maxi = 0, mai = 0;
  vector<vector<int>> v(300010);
  vector<int> row;
  vector<int> column;
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    cin >> k >> l;
    v[k - 1].push_back(l - 1);
    ara[k - 1] += 1;
    maxi = max(maxi, ara[k - 1]);
    bra[l - 1] += 1;
    mai = max(mai, bra[l - 1]);
  }

  for (int i = 0; i < h; i++) {
    if (ara[i] == maxi) {
      row.push_back(i);
    }
  }

  for (int i = 0; i < w; i++) {
    if (bra[i] == mai) {
      column.push_back(i);
    }
  }

  for (int i = 0; i < row.size(); i++) {
    int ct = 0;
    sort(v[row[i]].begin(), v[row[i]].end());
    int j = 0;
    int k = 0;
    while (1) {

      if (k == v[row[i]].size())
        break;
      if (j == column.size())
        break;
      if (v[row[i]][k] == column[j]) {
        ct++;
        j++;
        k++;
      } else if (v[row[i]][k] > column[j]) {
        j++;
      } else if (v[row[i]][k] < column[j]) {
        k++;
      }
    }
    /*for (int )
    for (int k=0;k<v[row[i]].size();k++){
            if (v[row[i]][k]>column[column.size()-1]){
                    continue;
            }

            for (int j=0;j<column.size();j++){

                    if (v[row[i]][k]==column[j]){
                            ct++;
                            break;
                    }
                    else if (v[row[i]][k]<column[j]){
                            break;
                    }

            }

    }*/
    if (ct != column.size()) {
      cout << maxi + mai;
      return 0;
    }
    // return 0;
  }
  cout << maxi + mai - 1;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int ara[300000];
int bra[300000];
int main() {
  int h, w, n, k, l;
  int maxi = 0, mai = 0;
  vector<vector<int>> v(300000);
  vector<int> row;
  vector<int> column;
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    cin >> k >> l;
    v[k - 1].push_back(l - 1);
    ara[k - 1] += 1;
    maxi = max(maxi, ara[k - 1]);
    bra[l - 1] += 1;
    mai = max(mai, bra[l - 1]);
  }

  for (int i = 0; i < h; i++) {
    if (ara[i] == maxi) {
      row.push_back(i);
    }
  }

  for (int i = 0; i < w; i++) {
    if (bra[i] == mai) {
      column.push_back(i);
    }
  }

  for (int i = 0; i < row.size(); i++) {
    int ct = 0;
    sort(v[row[i]].begin(), v[row[i]].end());
    int j = 0;
    int k = 0;
    while (1) {

      if (k == v[row[i]].size())
        break;
      if (j == column.size())
        break;
      if (v[row[i]][k] == column[j]) {
        ct++;
        j++;
        k++;
      }
      if (v[row[i]][k] > column[j]) {
        j++;
      } else if (v[row[i]][k] < column[j]) {
        k++;
      }
    }
    /*for (int )
    for (int k=0;k<v[row[i]].size();k++){
            if (v[row[i]][k]>column[column.size()-1]){
                    continue;
            }

            for (int j=0;j<column.size();j++){

                    if (v[row[i]][k]==column[j]){
                            ct++;
                            break;
                    }
                    else if (v[row[i]][k]<column[j]){
                            break;
                    }

            }

    }*/
    if (ct != column.size()) {
      cout << maxi + mai;
      return 0;
    }
    // return 0;
  }
  cout << maxi + mai - 1;

  return 0;
}