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

//
//  main.cpp

#include <iostream>
#include <vector>
using namespace std;

int main() {

  while (1) {
    int m;
    cin >> m;
    if (m == 0) {
      break;
    }
    vector<pair<int, int>> basecons;
    int x, y;
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      basecons.push_back(make_pair(x, y));
    }

    vector<pair<int, int>> allcons;

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      allcons.push_back(make_pair(x, y));
    }

    int count = 0;
    for (int i = 0; i < n; i++) { //??¨?????????????????????
      count = 0;
      int distancex = allcons[i].first - basecons[0].first;
      int distancey = allcons[i].second - basecons[0].second;
      //			bool isExistCons = false;
      for (int j = 0; j < m; j++) { //??¨????????¢??????????????¨
                                    //				bool isExistStar = false;
        for (int k = 0; k < n;
             k++) { //??¢????????????????????????????????¨?????????
          if (allcons[k].first == basecons[j].first + distancex &&
              allcons[k].second == basecons[j].second + distancey) {
            //						isExistStar = true;
            count++;
            break;
          } /*else{
//						isExistStar = false;
           }*/
        }
        /*
        if(isExistStar){
                isExistCons = true;
        }else{
                isExistCons = false;
                break;
        }*/
      }
      //			if(isExistCons){
      if (count == m) {
        cout << distancex << " " << distancey << endl;
        break;
      }
    }
  }
  return 0;
}

Error: -11

Fixed submission:

//
//  main.cpp

#include <iostream>
#include <vector>
using namespace std;

int main() {

  while (1) {
    int m;
    cin >> m;
    if (m == 0) {
      break;
    }
    vector<pair<int, int>> basecons;
    int x, y;
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      basecons.push_back(make_pair(x, y));
    }

    vector<int> y_of[1000001];
    vector<pair<int, int>> allcons;

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      y_of[x].push_back(y);
      allcons.push_back(make_pair(x, y));
    }

    for (int i = 0; i < allcons.size(); i++) { //??¨?????????????????????
      int distancex = allcons[i].first - basecons[0].first;
      int distancey = allcons[i].second - basecons[0].second;
      bool isExistCons = false;
      for (int j = 0; j < basecons.size(); j++) { //??¨????????¢??????????????¨
        bool isExistStar = false;
        if (basecons[j].first + distancex < 0)
          continue;
        for (int k = 0; k < y_of[basecons[j].first + distancex].size();
             k++) { //??¢????????????????????????????????¨?????????

          if (y_of[basecons[j].first + distancex][k] ==
              basecons[j].second + distancey) {
            isExistStar = true;
            break;
          } else {
            isExistStar = false;
          }
        }
        if (isExistStar) {
          isExistCons = true;
        } else {
          isExistCons = false;
          break;
        }
      }
      if (isExistCons) {
        cout << distancex << " " << distancey << endl;
        break;
      }
    }
  }
  return 0;
}