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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#define int long long
#define INF 100000000000
#define EPS 0.0000000001

using namespace std;
int movex[300000], movey[300000];
int graphx[300];
int graphy[300];
int photox[10100];
int photoy[1010];

void syoki() {
  for (int i = 0; i < 300000; i++) {
    movex[i] = 0;
    movey[i] = 0;
  }
  for (int i = 0; i < 1010; i++) {
    graphx[i] = 0;
    graphy[i] = 0;
    photox[i] = 0;
    photoy[i] = 0;
  }
}

signed main() {
  int m, n;
  int x, y;
  while (1) {
    syoki();
    cin >> m;
    if (m == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      graphx[i] = x;
      graphy[i] = y;
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      photox[i] = x;
      photoy[i] = y;
    }
    int k = 0;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        movex[k] = photox[j] - graphx[i];
        movey[k] = photoy[j] - graphy[i];
        k++;
      }
    }
    int cntx = 0;
    int cnty = 0;
    int ansx = 0, ansy = 0;
    sort(movex, movex + k);
    sort(movey, movey + k);
    for (int i = 0; i < k; i++) {
      if (movex[i] == movex[i + 1])
        cntx++;
      else
        cntx = 0;
      if (movey[i] == movey[i + 1])
        cnty++;
      else
        cnty = 0;
      if (cntx == m - 1)
        ansx = movex[i];
      if (cnty == m - 1)
        ansy = movey[i];
      // cout << movex[i] << " " << movey[i] << endl;
      // printf("[%d] [%d]",cntx,cnty);
      if (ansx && ansy)
        break;
    }
    cout << ansx << " " << ansy << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#define int long long
#define INF 100000000000
#define EPS 0.0000000001

using namespace std;
int movex[300], movey[300];
int graphx[300];
int graphy[300];
int photox[1010];
int photoy[1010];

void syoki() {
  for (int i = 0; i < 300; i++) {
    movex[i] = 0;
    movey[i] = 0;
    graphx[i] = 0;
    graphy[i] = 0;
  }
  for (int i = 0; i < 1010; i++) {
    photox[i] = 0;
    photoy[i] = 0;
  }
}

signed main() {
  int m, n;
  int x, y;
  while (1) {
    syoki();
    cin >> m;
    if (m == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      graphx[i] = x;
      graphy[i] = y;
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      photox[i] = x;
      photoy[i] = y;
    }
    int k = 0;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        movex[k] = photox[j] - graphx[i];
        movey[k] = photoy[j] - graphy[i];
        k++;
      }
    }
    int cntx = 0;
    int cnty = 0;
    int ansx = 0, ansy = 0;
    sort(movex, movex + k);
    sort(movey, movey + k);
    for (int i = 0; i < k; i++) {
      if (movex[i] == movex[i + 1])
        cntx++;
      else
        cntx = 0;
      if (movey[i] == movey[i + 1])
        cnty++;
      else
        cnty = 0;
      if (cntx == m - 1)
        ansx = movex[i];
      if (cnty == m - 1)
        ansy = movey[i];
      // cout << movex[i] << " " << movey[i] << endl;
      // printf("[%d] [%d]",cntx,cnty);
      if (ansx && ansy)
        break;
    }
    cout << ansx << " " << ansy << endl;
  }
  return 0;
}