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

#include <iostream>
using namespace std;

void drop(int x, int y, int xy[][10]) {
  if (x >= 0 && x < 10 && y >= 0 && y < 10)
    xy[x][y]++;
}

int main() {
  int xy[10][10] = {{0}};
  int x, y, size, num = 0, ans = 0;
  const int small = 5, medium = 9, big = 13;
  char c;

  int s[small][2] = {{0, 0}, {-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  int m[medium][2] = {{0, 0},   {-1, 0}, {1, 0},  {0, -1}, {0, 1},
                      {-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
  int b[big][2] = {{0, 0},   {-1, 0}, {1, 0},  {0, -1}, {0, 1},
                   {-1, -1}, {-1, 1}, {1, -1}, {1, 1},  {-2, 0},
                   {2, 0},   {0, -2}, {0, 2}};
  while (cin >> x >> c >> y >> c >> size) {
    if (size == 1)
      for (int i = 0; i < small; i++)
        drop(x + s[i][0], y + s[i][1], xy);
    else if (size == 2)
      for (int i = 0; i < medium; i++)
        drop(x + m[i][0], y + m[i][1], xy);
    else
      for (int i = 0; i < big; i++)
        drop(x + b[i][0], y + b[i][1], xy);
  }

  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++) {
      if (xy[i][j] == 0)
        num++;
      if (xy[i][j] > ans)
        ans = xy[i][j];
    }

  cout << num << endl;
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

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

static int ans = 0;

void small(vector<vector<int>> &paper, int x, int y) {
  x += 2;
  y += 2;
  paper[x][y]++;
  if (paper[x][y] > ans)
    ans = paper[x][y];
  paper[x - 1][y]++;
  if (paper[x - 1][y] > ans && x - 1 >= 2)
    ans = paper[x - 1][y];
  paper[x + 1][y]++;
  if (paper[x + 1][y] > ans && x + 1 <= 11)
    ans = paper[x + 1][y];
  paper[x][y - 1]++;
  if (paper[x][y - 1] > ans && y - 1 >= 2)
    ans = paper[x][y - 1];
  paper[x][y + 1]++;
  if (paper[x][y + 1] > ans && y + 1 <= 11)
    ans = paper[x][y + 1];
}

void medium(vector<vector<int>> &paper, int x, int y) {
  small(paper, x, y);
  x += 2;
  y += 2;
  paper[x - 1][y - 1]++;
  if (paper[x - 1][y - 1] > ans && x - 1 >= 2 && y - 1 >= 2)
    ans = paper[x - 1][y - 1];
  paper[x - 1][y + 1]++;
  if (paper[x - 1][y + 1] > ans && x - 1 >= 2 && y + 1 <= 11)
    ans = paper[x - 1][y + 1];
  paper[x + 1][y - 1]++;
  if (paper[x + 1][y - 1] > ans && x + 1 <= 11 && y - 1 >= 2)
    ans = paper[x + 1][y - 1];
  paper[x + 1][y + 1]++;
  if (paper[x + 1][y + 1] > ans && x + 1 <= 11 && y + 1 <= 11)
    ans = paper[x + 1][y + 1];
}

void large(vector<vector<int>> &paper, int x, int y) {
  medium(paper, x, y);
  x += 2;
  y += 2;
  paper[x][y - 2]++;
  if (paper[x][y - 2] > ans && y - 2 >= 2)
    ans = paper[x][y - 2];
  paper[x][y + 2]++;
  if (paper[x][y + 2] > ans && y + 2 <= 11)
    ans = paper[x][y + 2];
  paper[x - 2][y]++;
  if (paper[x - 2][y] > ans && x - 2 >= 2)
    ans = paper[x - 2][y];
  paper[x + 2][y]++;
  if (paper[x + 2][y] > ans && x + 2 <= 11)
    ans = paper[x + 2][y];
}

int main() {
  vector<vector<int>> paper(14, vector<int>(14));
  int x, y, size;
  string str;
  while (true) {
    getline(cin, str);
    x = str[0] - '0';
    y = str[2] - '0';
    size = str[4] - '0'; // cout << "OK\\n";
    if (size == 1)
      small(paper, x, y);
    else if (size == 2)
      medium(paper, x, y);
    else
      large(paper, x, y);
    //    cout << "NOK\\n";
  }
  cout << ans << endl;
  return 0;
}