alexjercan/bugnet huggingface dataset:
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {

  int i, j, r, c;
  int num[101][101] = {};

  cin >> r >> c;

  for (i = 0; i < r; i++)
    for (j = 0; j < c; j++)
      cin >> num[i][j];

  for (i = 0; i < r; i++) {

    for (j = 0; j < c; j++) {
      num[i][c] += num[i][j];
    }
  }

  for (i = 0; i < c; i++) {

    for (j = 0; j < r; j++) {

      num[r][i] += num[j][i];
    }
    num[r][c] += num[r][i];
  }

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {

      cout << num[i][j] << " ";
    }
    cout << num[i][c] << "\\n";
  }
  for (i = 0; i < c; i++) {

    cout << num[r][i] << " ";
  }
  cout << num[r][c];
  cout << "\\n";

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int i, j, r, c;
  int num[1000000000][100];

  cin >> r >> c;

  for (i = 0; i < r; i++) {

    for (j = 0; j < c; j++) {

      cin >> num[i][j];
    }
  }

  for (i = 0; i < r; i++) {

    for (j = 0; j < c; j++) {

      num[i][c] += num[i][j];
    }
  }

  for (i = 0; i < c; i++) {

    for (j = 0; j < r; j++) {

      num[r][i] += num[j][i];
    }
    num[r][c] += num[r][i];
  }

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {

      cout << num[i][j] << " ";
    }
    cout << num[i][c] << "\\n";
  }
  for (i = 0; i < c; i++) {

    cout << num[r][i] << " ";
  }
  cout << num[r][c];
  cout << "\\n";

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main() {
  int r, c;
  int n[101][101] = {};
  int i, j;
  int sum;
  scanf("%d %d", &r, &c);
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      scanf("%d", &n[i][j]);
      n[r][c] += n[i][j];
    }
  }
  for (i = 0; i < r; i++) {

    for (j = 0; j < c; j++) {
      n[i][c] += n[i][j];
    }
  }
  for (j = 0; j < c; j++) {
    for (i = 0; i < r; i++) {
      n[r][j] += n[i][j];
    }
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j <= c; j++) {
      if (j == c) {
        printf("%d", n[i][j]);
      } else {
        printf("%d ", n[i][j]);
      }
    }
    printf("\\n");
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>

int main() {
  int r, c;
  int n[100][100] = {};
  int i, j;
  int sum;
  scanf("%d %d", &r, &c);
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      scanf("%d", &n[i][j]);
      n[r][c] += n[i][j];
    }
  }
  for (i = 0; i < r; i++) {

    for (j = 0; j < c; j++) {
      n[i][c] += n[i][j];
    }
  }
  for (j = 0; j < c; j++) {
    for (i = 0; i < r; i++) {
      n[r][j] += n[i][j];
    }
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j <= c; j++) {
      if (j == c) {
        printf("%d", n[i][j]);
      } else {
        printf("%d ", n[i][j]);
      }
    }
    printf("\\n");
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c, graph[101][101];
  cin >> r >> c;

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      graph[i][j] = 0;
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> graph[i][j];
    }
    for (int j = 0; j < c; j++) {
      graph[i][c] += graph[i][j];
    }
  }

  for (int j = 0; j < c + 1; j++) {
    for (int i = 0; i < r; i++) {
      graph[r][j] += graph[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      printf("%d", graph[i][j]);
      if (j != c)
        printf(" ");
    }
    printf("\\n");
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c, graph[101][101];
  cin >> r >> c;

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      graph[i][j] = 0;
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> graph[i][j];
    }
    for (int j = 0; j < c; j++) {
      graph[i][c] += graph[i][j];
    }
  }

  for (int j = 0; j < c + 1; j++) {
    for (int i = 0; i < r; i++) {
      graph[r][j] += graph[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      printf("%d", graph[i][j]);
      if (j != c)
        printf(" ");
    }
    printf("\\n");
  }

  while (1) {
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main(void) {
  int r, c, i, j, k;
  int a[102][102] = {};

  cin >> r >> c;

  for (j = 1; j <= r; j++) {
    a[c + 1][j] = 0;
    for (i = 1; i <= c; i++) {
      cin >> a[i][j];
      a[c + 1][j] = a[c + 1][j] + a[i][j];
    }
  }

  for (i = 1; i <= c + 1; i++) {
    a[i][r + 1] = 0;
    for (j = 1; j <= r; j++) {
      a[i][r + 1] = a[i][r + 1] + a[i][j];
    }
  }

  for (j = 1; j <= r + 1; j++) {
    for (i = 1; i <= c + 1; i++) {
      cout << a[i][j];
      if (i != c + 1)
        cout << " ";
    }
    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int r, c, i, j, k;
  int a[101][101] = {};

  cin >> r >> c;

  for (j = 1; j <= r; j++) {
    a[c + 1][j] = 0;
    for (i = 1; i <= c; i++) {
      cin >> a[i][j];
      a[c + 1][j] = a[c + 1][j] + a[i][j];
    }
  }

  for (i = 1; i <= c + 1; i++) {
    a[i][r + 1] = 0;
    for (j = 1; j <= r; j++) {
      a[i][r + 1] = a[i][r + 1] + a[i][j];
    }
  }

  for (j = 1; j <= r + 1; j++) {
    for (i = 1; i <= c + 1; i++) {
      cout << a[i][j];
      if (i != c + 1)
        cout << " ";
    }
    cout << endl;
  }

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int r, c, i, j;
  int table[101][101] = {0};
  cin >> r >> c;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> table[i][j];
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
      table[r][c] += table[i][j];
    }
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j <= c; j++) {
      cout << table[i][j];
      if (j < c)
        cout << " ";
      else
        cout << "\\n";
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int r, c, i, j;
  int table[100][100] = {0};
  cin >> r >> c;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> table[i][j];
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
      table[r][c] += table[i][j];
    }
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j <= c; j++) {
      cout << table[i][j];
      if (j < c)
        cout << " ";
      else
        cout << "\\n";
    }
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int a[101][101] = {{}};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
      a[r][c] += a[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
      else
        cout << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int a[100][100] = {{}};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
      a[r][c] += a[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
      else
        cout << endl;
    }
  }

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int r, c, M[101][101];

  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> M[i][j];

  for (int i = 0; i < r; i++)
    M[i][c] = 0;
  for (int j = 0; j < c; j++)
    M[r][j] = 0;
  M[r][c] = 0;

  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) {
      M[i][c] += M[i][j];
      M[r][j] += M[i][j];
      M[r][c] += M[i][j];
    }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }

    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  int r, c, M[100][100];

  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> M[i][j];

  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) {
      M[i][c] += M[i][j];
      M[r][j] += M[i][j];
      M[r][c] += M[i][j];
    }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define M 1000

int main() {
  int r, c, mat[M][M];

  for (int i = 0; i < M; i++)
    for (int j = 0; j < M; j++)
      mat[i][j] = 0;

  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> mat[i][j];

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[i][c] += mat[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[r][j] += mat[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[r][c] += mat[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (!j)
        cout << mat[i][j];
      else
        cout << ' ' << mat[i][j];
    }
    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define M 100

int main() {
  int r, c, mat[M][M];

  for (int i = 0; i < M; i++)
    for (int j = 0; j < M; j++)
      mat[i][j] = 0;

  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> mat[i][j];

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[i][c] += mat[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[r][j] += mat[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[r][c] += mat[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (!j)
        cout << mat[i][j];
      else
        cout << ' ' << mat[i][j];
    }
    cout << endl;
  }

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c;
  int i, j;
  int d[101][101];
  int cc = 0;
  int cr = 0;

  cin >> r >> c;

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> d[i][j];
      cc = cc + d[i][j];
      if (j == c - 1)
        d[i][j + 1] = cc;
    }
    cc = 0;
  }

  for (j = 0; j < c + 1; j++) {
    for (i = 0; i < r; i++) {
      cr = cr + d[i][j];
      if (i == r - 1)
        d[i + 1][j] = cr;
    }
    cr = 0;
  }

  for (i = 0; i < r + 1; i++) {
    for (j = 0; j < c + 1; j++) {
      if (j == c) {
        cout << d[i][j] << endl;
        ;
      } else {
        cout << d[i][j] << ' ';
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c;
  int i, j;
  int d[100][100];
  int cc = 0;
  int cr = 0;

  cin >> r >> c;

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> d[i][j];
      cc = cc + d[i][j];
      if (j == c - 1)
        d[i][j + 1] = cc;
    }
    cc = 0;
  }

  for (j = 0; j < c + 1; j++) {
    for (i = 0; i < r; i++) {
      cr = cr + d[i][j];
      if (i == r - 1)
        d[i + 1][j] = cr;
    }
    cr = 0;
  }

  for (i = 0; i < r + 1; i++) {
    for (j = 0; j < c + 1; j++) {
      if (j == c) {
        cout << d[i][j] << endl;
        ;
      } else {
        cout << d[i][j] << ' ';
      }
    }
  }

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int r, c, i, j;
  int n, s;
  int w = 0;

  cin >> r >> c;

  int a[r][c];

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> a[i][j];
    }
  }

  for (i = 0; i < r; i++) {
    n = 0;
    for (j = 0; j < c; j++) {
      n = n + a[i][j];
      cout << a[i][j] << " ";
    }
    cout << n << endl;
    ;
  }

  for (j = 0; j < c; j++) {
    s = 0;
    for (i = 0; i < r; i++) {
      s = s + a[i][j];
    }
    w = w + s;
    cout << s << " ";
  }

  cout << w << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int r, c, i, j;
  int n = 0;
  int s = 0;
  int sum = 0;

  cin >> r >> c;

  int a[r][c];

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> a[i][j];
    }
  }

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      n = n + a[i][j];
      cout << a[i][j] << " ";
    }
    cout << n << endl;
  }

  for (j = 0; j < c; j++) {
    for (i = 0; i < r; j++) {
      s = s + a[i][j];
    }
    cout << s << " ";
  }
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      sum = sum + a[i][j];
    }
  }
  cout << sum << endl;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int r, c, a[101][101] = {0};

  cin >> r >> c;
  // DWORD start = GetTickCount();//スタート時間

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
    }
    a[r][c] += a[i][c];
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j < c) {
        cout << ' ';
      }
    }
    cout << endl;
  }

  // DWORD end = GetTickCount();//終了時間
  // cout << "time = " << (double)(end - start) / 1000 << "sec.\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int r, c, a[100][100] = {0};

  cin >> r >> c;
  // DWORD start = GetTickCount();//スタート時間

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
    }
    a[r][c] += a[i][c];
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j < c) {
        cout << ' ';
      }
    }
    cout << endl;
  }

  // DWORD end = GetTickCount();//終了時間
  // cout << "time = " << (double)(end - start) / 1000 << "sec.\\n";

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long r, c;
  cin >> r >> c;
  // r = 2;
  // c = 2;
  vector<vector<long>> sp(r);
  for (long i = 0; i < r; i++) {
    sp[i].resize(c);
  }
  for (long i = 0; i < r; i++) {
    for (long j = 0; j < c; j++) {
      cin >> sp[i][j];
    }
  }
  vector<long> rsum(r, 0);
  vector<long> csum(c, 0);
  for (long i = 0; i < r; i++) {
    for (long j = 0; j < c; j++) {
      rsum[i] += sp[i][j];
    }
  }
  for (long i = 0; i < c; i++) {
    for (long j = 0; j < r; j++) {
      csum[i] += sp[j][i];
    }
  }
  long sum = 0;
  for (long i = 0; i < r; i++) {
    sum += rsum[i];
  }
  for (long i = 0; i < r; i++) {
    for (long j = 0; j < c; j++) {
      cout << sp[i][j] << " ";
    }
    cout << rsum[i] << endl;
  }
  for (long i = 0; i < c; i++) {
    cout << csum[i] << " ";
  }
  cout << sum << endl;
  /*
  vector< vector<long> > newsp(r + 1);
  for (long i = 0; i < r + 1; i++){
          newsp[i].resize(c + 1);
  }
  for (long i = 0; i < r + 1; i++){
          for (long j = 0; j < c + 1; j++){
                  if (i < r && j < c) newsp[i][j] = sp[i][j];
                  else if (i = r && j < c) newsp[i][j] = csum[j];
                  else if (j = c && i < r) newsp[i][j] = rsum[i];
                  else newsp[i][j] = sum;
          }
  }
  for (long i = 0; i < r + 1; i++){
          for (long j = 0; j < c + 1; j++){
                  cout << newsp[i][j];
          }
          cout << endl;
  }
  */
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long r, c;
  cin >> r >> c;
  vector<vector<long>> sp(r);
  for (long i = 0; i < r; i++) {
    sp[i].resize(c);
  }
  vector<long> rsum(r, 0);
  vector<long> csum(c, 0);
  for (long i = 0; i < r; i++) {
    for (long j = 0; j < c; j++) {
      rsum[i] += sp[i][j];
    }
  }
  for (long i = 0; i < c; i++) {
    for (long j = 0; j < r; j++) {
      csum[i] += sp[j][i];
    }
  }
  long sum = 0;
  for (long i = 0; i < r; i++) {
    sum += rsum[i];
  }
  vector<vector<long>> newsp(r + 1);
  for (long i = 0; i < r + 1; i++) {
    newsp[i].resize(c + 1);
  }
  for (long i = 0; i < r + 1; i++) {
    for (long j = 0; j < c + 1; j++) {
      if (i < r && j < c)
        newsp[i][j] = sp[i][j];
      else if (i = r && j < c)
        newsp[i][j] = csum[j];
      else if (j = c && i < r)
        newsp[i][j] = rsum[i];
      else
        newsp[i][j] = sum;
    }
  }
  for (long i = 0; i < r + 1; i++) {
    for (long j = 0; j < c + 1; j++) {
      cout << newsp[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int r, c, s;
  int **a;
  cin >> r >> c;
  a = new int *[r + 1];
  for (int i = 0; i < r; ++i) {
    a[i] = new int[c + 1];
    s = 0;
    for (int j = 0; j < c; ++j) {
      cin >> a[i][j];
      s += a[i][j];
    }
    a[i][c] = s;
  }
  a[r] = new int[c + 1];
  for (int j = 0; j < c; ++j) {
    s = 0;
    for (int i = 0; i < r; ++i)
      s += a[i][j];
    a[r][j] = s;
  }

  for (int i = 0; i < r; ++i) {
    for (int j = 0; j <= c; ++j) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
    }
    cout << endl;
  }

  s = 0;
  for (int i = 0; i < c; ++i) {
    s += a[r][i];
    cout << a[r][i] << " ";
  }
  cout << s << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int r, c, s;
  int **a;
  cin >> r >> c;
  a = new int *[r + 1];
  for (int i = 0; i < r; ++i) {
    a[i] = new int[c + 1];
    s = 0;
    for (int j = 0; j < c; ++j) {
      cin >> a[i][j];
      s += a[i][j];
    }
    a[i][c] = s;
  }

  for (int j = 0; j < c; ++j) {
    s = 0;
    for (int i = 0; i < r; ++i)
      s += a[i][j];
    a[r][j] = s;
  }

  for (int i = 0; i < r; ++i) {
    for (int j = 0; j <= c; ++j)
      cout << a[i][j] << " ";
    cout << endl;
  }

  s = 0;
  for (int i = 0; i < c; ++i) {
    s += a[r][i];
    cout << a[r][i] << " ";
  }
  cout << s << endl;
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int mat[101][101] = {};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> mat[i][j];
      mat[i][c] += mat[i][j];
      mat[r][j] += mat[i][j];
      mat[r][c] += mat[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if (j == c)
        cout << mat[i][j] << endl;
      else
        cout << mat[i][j] << " ";
    }
  }
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int mat[100][100];

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> mat[i][j];
      mat[i][c] += mat[i][j];
      mat[r][j] += mat[i][j];
      mat[r][c] += mat[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if (j == c)
        cout << mat[i][j] << endl;
      else
        cout << mat[i][j] << " ";
    }
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

int main() {
  int r, c, i;
  std::cin >> r >> c;
  int list[101][101] = {0};
  for (int a = 0; a < r; a++) {
    for (int b = 0; b < c; b++) {
      std::cin >> i;
      list[a][b] = i;
      list[a][c] = list[a][c] + i;
      list[r][b] = list[r][b] + i;
      list[r][c] = list[r][c] + i;
    }
  }
  for (int d = 0; d <= r; d++) {
    for (int e = 0; e <= c; e++) {
      if (e < c) {
        std::cout << list[d][e] << " ";
      } else {
        std::cout << list[d][e];
      }
    }
    std::cout << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

int main() {
  int r, c, i;
  std::cin >> r >> c;
  int list[100][100] = {0};
  for (int a = 0; a < r; a++) {
    for (int b = 0; b < c; b++) {
      std::cin >> i;
      list[a][b] = i;
      list[a][c] = list[a][c] + i;
      list[r][b] = list[r][b] + i;
      list[r][c] = list[r][c] + i;
    }
  }
  for (int d = 0; d <= r; d++) {
    for (int e = 0; e <= c; e++) {
      if (e < c) {
        std::cout << list[d][e] << " ";
      } else {
        std::cout << list[d][e];
      }
    }
    std::cout << std::endl;
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int arr[199][199];
int reg[199];

int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < a; i++) {
    int sum = 0, c = 0;
    for (int j = 0; j < b; j++) {
      if (c != 0)
        cout << " ";
      cout << arr[i][j];
      sum += arr[i][j];
      reg[j] += arr[i][j];
      c++;
    }
    cout << " " << sum;
    reg[b] += sum;
    cout << endl;
  }
  int c = 0;
  for (int i = 0; i <= b; i++) {
    if (c != 0)
      cout << " ";
    cout << reg[i];
    c++;
  }
  cout << endl;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  freopen("input.txt", "r", stdin);
  int n, f, k = 0, m = 0, max = 0;
  cin >> n >> f;
  int a[n + 1][f + 1];
  for (int i = 0; i < n; i++) {
    k = 0;
    for (int j = 0; j < f; j++) {
      cin >> a[i][j];
      k += a[i][j];
    }
    a[i][f] = k;
  }
  for (int i = 0; i < f; i++) {
    m = 0;
    for (int j = 0; j < n; j++) {
      m += a[j][i];
    }
    a[n][i] = m;
  }
  for (int i = 0; i < f; i++) {
    max += a[n][i];
  }
  a[n][f] = max;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= f; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int r, c;
  cin >> r >> c;
  vector<vector<int>> v(r + 1, vector<int>(c + 1, 0));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> v[i][j];
    }
  }

  for (int i = 0; i < r; i++) {

    for (int j = 0; j < c; j++) {
      v[i][c] += v[i][j];
    }
  }

  for (int i = 0; i < c + 1; i++) {
    for (int j = 0; j < r; j++) {
      v[r][i] += v[j][i];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      cout << v[i][j];
      if (j < c) {
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;
}


Error: -11

Fixed submission:

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

int main() {
  int r, c;
  cin >> r >> c;
  vector<vector<int>> v(r + 1, vector<int>(c + 1, 0));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> v[i][j];
    }
  }

  for (int i = 0; i < r; i++) {

    for (int j = 0; j < c; j++) {
      v[i][c] += v[i][j];
    }
  }

  for (int i = 0; i < c + 1; i++) {
    for (int j = 0; j < r; j++) {
      v[r][i] += v[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      cout << v[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}