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

#include <iostream>
using namespace std;
struct v {
  int a;
  int c;
  int d;
  int e;
};
int main() {
  v w[1000];
  int n, j, m, i, d1[4][11] = {0}, d2[4][11] = {0}, d3[4][11] = {0},
                  d4[4][11] = {0};
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> w[i].a >> w[i].c >> w[i].d >> w[i].e;
    if (w[i].a == 1) {
      d1[w[i].c][w[i].d] += w[i].e;
    }
    if (w[i].a == 2) {
      d2[w[i].c][w[i].d] += w[i].e;
    }
    if (w[i].a == 3) {
      d3[w[i].c][w[i].d] += w[i].e;
    }
    if (w[i].a == 4) {
      d4[w[i].c][w[i].d] += w[i].e;
    }
  }
  for (m = 0; m < 4; m++) {
    if (m == 0) {
      for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 10; j++) {
          if (j != 10)
            cout << " " << d1[i][j];
          else
            cout << " " << d1[i][j] << endl;
        }
      }
      for (i = 0; i < 20; i++) {
        cout << '#';
      }
      cout << endl;
    }
    if (m == 1) {
      for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 10; j++) {
          if (j != 10)
            cout << " " << d2[i][j];
          else
            cout << " " << d2[i][j] << endl;
        }
      }
      for (i = 0; i < 20; i++) {
        cout << '#';
      }
      cout << endl;
    }
    if (m == 2) {
      for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 10; j++) {
          if (j != 10)
            cout << " " << d3[i][j];
          else
            cout << " " << d3[i][j] << endl;
        }
      }
      for (i = 0; i < 20; i++) {
        cout << '#';
      }
      cout << endl;
    }
    if (m == 3) {
      for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 10; j++) {
          if (j != 10)
            cout << " " << d4[i][j];
          else
            cout << " " << d4[i][j] << endl;
        }
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
struct v {
  int a;
  int c;
  int d;
  int e;
};
int main() {
  v w[200];
  int n, j, m, i, d1[4][11] = {0}, d2[4][11] = {0}, d3[4][11] = {0},
                  d4[4][11] = {0};
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> w[i].a >> w[i].c >> w[i].d >> w[i].e;
    if (w[i].a == 1) {
      d1[w[i].c][w[i].d] += w[i].e;
    }
    if (w[i].a == 2) {
      d2[w[i].c][w[i].d] += w[i].e;
    }
    if (w[i].a == 3) {
      d3[w[i].c][w[i].d] += w[i].e;
    }
    if (w[i].a == 4) {
      d4[w[i].c][w[i].d] += w[i].e;
    }
  }
  for (m = 0; m < 4; m++) {
    if (m == 0) {
      for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 10; j++) {
          if (j != 10)
            cout << " " << d1[i][j];
          else
            cout << " " << d1[i][j] << endl;
        }
      }
      for (i = 0; i < 20; i++) {
        cout << '#';
      }
      cout << endl;
    }
    if (m == 1) {
      for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 10; j++) {
          if (j != 10)
            cout << " " << d2[i][j];
          else
            cout << " " << d2[i][j] << endl;
        }
      }
      for (i = 0; i < 20; i++) {
        cout << '#';
      }
      cout << endl;
    }
    if (m == 2) {
      for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 10; j++) {
          if (j != 10)
            cout << " " << d3[i][j];
          else
            cout << " " << d3[i][j] << endl;
        }
      }
      for (i = 0; i < 20; i++) {
        cout << '#';
      }
      cout << endl;
    }
    if (m == 3) {
      for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 10; j++) {
          if (j != 10)
            cout << " " << d4[i][j];
          else
            cout << " " << d4[i][j] << endl;
        }
      }
    }
  }
  return 0;
}