Problem p02409 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;          // n??¶????????±
  int b, f, r, v; // b:?£? f:??? r:???????????¨?±? v:?¢???????????????°
  int house1[4][11] = {0}; // 1?£?
  int house2[4][11] = {0}; // 2?£?
  int house3[4][11] = {0}; // 3?£?
  int house4[4][11] = {0}; // 4?£?

  cin >> n;

  //?????±?????\\???
  for (int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;

    if (b == 1) // 1?£?????????£??????
    {
      for (int j = 1; j <= 3; j++) {
        if (f == j) //??????????????°???
        {
          for (int k = 1; k <= 10; k++) //??????????????¨?±????
          {
            if (k == r) {
              house1[f][r] = house1[f][r] +
                             v; //?????????0???????§?????????????1????????????
            }
          }
        }
      }
    }

    if (b == 2) // 2?£?????????£??????
    {
      for (int j = 1; j <= 3; j++) {
        if (f == j) //??????????????°???
        {
          for (int k = 1; k <= 10; k++) //??????????????¨?±????
          {
            if (k == r) {
              house2[f][r] = house2[f][r] +
                             v; //?????????0???????§?????????????1????????????
            }
          }
        }
      }
    }

    if (b == 3) // 3?£?????????£??????
    {
      for (int j = 1; j <= 3; j++) {
        if (f == j) //??????????????°???
        {
          for (int k = 1; k <= 10; k++) //??????????????¨?±????
          {
            if (k == r) {
              house3[f][r] = house3[f][r] +
                             v; //?????????0???????§?????????????1????????????
            }
          }
        }
      }
    }

    if (b == 4) // 4?£?????????£??????
    {
      for (int j = 1; j <= 3; j++) {
        if (f == j) //??????????????°???
        {
          for (int k = 1; k <= 10; k++) //??????????????¨?±????
          {
            if (k == r) {
              house4[f][r] = house4[f][r] +
                             v; //?????????0???????§?????????????1????????????
            }
          }
        }
      }
    }
  }

  /*??????*/
  for (int j = 1; j <= 3; j++) {
    for (int k = 1; k <= 10; k++) {
      cout << " " << house1[j][k];
    }
    cout << "\\n";
  }
  cout << "####################"
       << "\\n";

  for (int j = 1; j <= 3; j++) {
    for (int k = 1; k <= 10; k++) {
      cout << " " << house2[j][k];
    }
    cout << "\\n";
  }
  cout << "####################"
       << "\\n";

  for (int j = 1; j <= 3; j++) {
    for (int k = 1; k <= 10; k++) {
      cout << " " << house3[j][k];
    }
    cout << "\\n";
  }
  cout << "####################"
       << "\\n";

  for (int j = 1; j <= 3; j++) {
    for (int k = 1; k <= 10; k++) {
      cout << " " << house4[j][k];
    }
    cout << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;          // n??¶????????±
  int b, f, r, v; // b:?£? f:??? r:???????????¨?±? v:?¢???????????????°
  int house1[3][10] = {0}; // 1?£?
  int house2[3][10] = {0}; // 2?£?
  int house3[3][10] = {0}; // 3?£?
  int house4[3][10] = {0}; // 4?£?

  cin >> n;

  while (1) {
    //?????±?????\\???
    for (int i = 0; i < n; i++) {
      cin >> b >> f >> r >> v;

      if (b == 1) // 1?£?????????£??????
      {
        for (int j = 0; j < 3; j++) {
          if (f == j + 1) //??????????????°???
          {
            for (int k = 0; k < 10; k++) //??????????????¨?±????
            {
              if (k == r) {
                house1[f - 1][r - 1] =
                    house1[f - 1][r - 1] +
                    v; //?????????0???????§?????????????1????????????
              }
            }
          }
        }
      }

      if (b == 2) // 2?£?????????£??????
      {
        for (int j = 0; j < 3; j++) {
          if (f == j + 1) //??????????????°???
          {
            for (int k = 0; k < 10; k++) //??????????????¨?±????
            {
              if (k == r) {
                house2[f - 1][r - 1] =
                    house2[f - 1][r - 1] +
                    v; //?????????0???????§?????????????1????????????
              }
            }
          }
        }
      }

      if (b == 3) // 3?£?????????£??????
      {
        for (int j = 0; j < 3; j++) {
          if (f == j + 1) //??????????????°???
          {
            for (int k = 0; k < 10; k++) //??????????????¨?±????
            {
              if (k == r) {
                house3[f - 1][r - 1] =
                    house3[f - 1][r - 1] +
                    v; //?????????0???????§?????????????1????????????
              }
            }
          }
        }
      }

      if (b == 4) // 4?£?????????£??????
      {
        for (int j = 0; j < 3; j++) {
          if (f == j + 1) //??????????????°???
          {
            for (int k = 0; k < 10; k++) //??????????????¨?±????
            {
              if (k == r) {
                house4[f - 1][r - 1] =
                    house4[f - 1][r - 1] +
                    v; //?????????0???????§?????????????1????????????
              }
            }
          }
        }
      }
    }

    /*??????*/
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        cout << house1[j][k] << " ";
      }
      cout << "\\n";
    }
    cout << "####################"
         << "\\n";

    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        cout << house2[j][k] << " ";
      }
      cout << "\\n";
    }
    cout << "####################"
         << "\\n";

    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        cout << house3[j][k] << " ";
      }
      cout << "\\n";
    }
    cout << "####################"
         << "\\n";

    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        cout << house4[j][k] << " ";
      }
      cout << "\\n";
    }
  }

  return 0;
}