alexjercan/bugnet huggingface dataset:
Problem p00278 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, q;
int s[1000000];
int ss[1000000];
multiset<int> S;

bool check(int y, int x) {
  vector<pair<int, int>> v;
  v.push_back(make_pair(0, 0));
  for (multiset<int>::iterator it = S.begin(); it != S.end(); ++it) {
    int L = lower_bound(ss, ss + n, *it - y) - ss;
    int R = upper_bound(ss, ss + n, *it) - ss;
    v.push_back(make_pair(L, R));
  }
  v.push_back(make_pair(n, n));

  for (int i = 0; i + 1 < v.size(); i++) {
    int diff = v[i + 1].first - v[i].second;
    x -= max(0, diff);
    if (x < 0)
      return false;
  }

  return true;
}

int main() {
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; i++)
    scanf("%d", s + i);
  for (int i = 0; i < n; i++)
    ss[i] = s[i];
  sort(ss, ss + n);
  for (int i = 0; i < q; i++) {
    string com;
    int x;

    cin >> com >> x;
    if (com == "ADD")
      S.insert(s[--x]);
    else if (com == "REMOVE")
      S.erase(S.find(s[--x]));
    else {
      int l = -1, r = 1e9 + 2;
      while (l + 1 < r) {
        int m = (l + r) / 2;
        if (check(m, x))
          r = m;
        else
          l = m;
      }
      if (l + 1 > (int)1e9)
        puts("NA");
      else
        printf("%d\\n", l + 1);
    }
  }
}

Error: TLE

Fixed submission:

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

int n, q;
int s[1000000];
int ss[1000000];
multiset<int> S;
vector<int> v;

bool check(int y, int x) {
  vector<int>::iterator it = v.begin();
  for (int i = 0; i < n; i++) {
    while (it != v.end() && ss[i] > *it)
      ++it;
    if (it == v.end())
      x--;
    else if (ss[i] + y < *it)
      x--;
    if (x < 0)
      return false;
  }

  return true;
}

int main() {
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; i++)
    scanf("%d", s + i);
  for (int i = 0; i < n; i++)
    ss[i] = s[i];
  sort(ss, ss + n);
  for (int i = 0; i < q; i++) {
    string com;
    int x;

    cin >> com >> x;
    if (com == "ADD")
      S.insert(s[--x]);
    else if (com == "REMOVE")
      S.erase(S.find(s[--x]));
    else {
      v.clear();
      for (multiset<int>::iterator it = S.begin(); it != S.end(); ++it) {
        v.push_back(*it);
      }

      int l = -1, r = 1e9 + 2;
      while (l + 1 < r) {
        int m = (l + r) / 2;
        if (check(m, x))
          r = m;
        else
          l = m;
      }
      if (l + 1 > (int)1e9)
        puts("NA");
      else
        printf("%d\\n", l + 1);
    }
  }
}
Problem p00280 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int J, Y;

void t(int j, int y, string str) {
  if (j > J || y > Y)
    return;
  if (j == J && y == Y) {
    cout << str << endl;
    return;
  }
  if (j == 5 && y == 5) {
    return;
  }
  if ((j <= 3 && y >= 5) || (j >= 5 && y <= 3)) {
    return;
  }

  t(j + 1, y, str + "A");
  t(j, y + 1, str + "B");
}

int main() {
  scanf("%d %d", &J, &Y);

  t(0, 0, "");
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int J, Y;

void t(int j, int y, string str) {
  if (j > J && y > Y)
    return;
  if (j == J && y == Y) {
    cout << str << endl;
    return;
  }
  if (j == 5 && y == 5) {
    return;
  }
  if ((j <= 3 && y >= 5) || (j >= 5 && y <= 3)) {
    return;
  }

  t(j + 1, y, str + "A");
  t(j, y + 1, str + "B");
}

int main() {
  scanf("%d %d", &J, &Y);

  t(0, 0, "");
}
Problem p00280 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int a, b;
void rec(string s, int x, int y) {
  if (a == x && b == y) {
    cout << s << endl;
    return;
  }
  if ((x < 4 || y < 4) && (x == 5 || y == 5))
    return;
  if (x + y > 9)
    return;
  rec(s + "A", x + 1, y);
  rec(s + "B", x, y + 1);
}
int main() {
  scanf("%d%d", &a, &b);
  rec("", 0, 0);
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int a, b;
void rec(string s, int x, int y) {
  if (a == x && b == y) {
    cout << s << endl;
    return;
  }
  if ((x < 4 || y < 4) && (x == 5 || y == 5))
    return;
  rec(s + "A", x + 1, y);
  rec(s + "B", x, y + 1);
}
int main() {
  scanf("%d%d", &a, &b);
  rec("", 0, 0);
}
Problem p00280 (C++) — buggy submission, verdict: Runtime Error

//
//  0285.cpp
//
//
//  Created by Minote Tomoki on 2015/06/01.
//
//

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>

typedef struct _tree {
  std::string *val;
  struct _tree *left;
  struct _tree *right;
} node;

int offset = 0;

node *state(int j, int i, int tj, int ty, std::string output) {
  node *r;

  r = (node *)malloc(sizeof(node));
  r->val = new std::string(output);
  r->left = NULL;
  r->right = NULL;

  if (j == tj && ty == i)
    return r;

  if ((i <= 3 && j == 5) || (i == 5 && j <= 3)) {
    return NULL;
  } else if ((i > 4 && j > 4) && (i - j) * (i - j) > 4) {
    return NULL;
  }

  if (j < tj)
    r->left = state(j + 1, i, tj, ty, "A");
  if (i < ty)
    r->right = state(j, i + 1, tj, ty, "B");
  return r;
}

void trace(node *r, std::string str) {
  str += *(r->val);

  if (r->left == NULL && r->right == NULL) {
    std::cout << str << std::endl;
  }

  if (r->left != NULL)
    trace(r->left, str);
  if (r->right != NULL)
    trace(r->right, str);
}

void freetree(node *n) {
  if (n->left != NULL)
    freetree(n->left);
  if (n->right != NULL)
    freetree(n->right);
  free(n);
}

int main(void) {
  int j;
  int y;

  std::string str;

  node *root = NULL;

  scanf("%d %d", &j, &y);
  if (j == 0 && y == 0)
    return 0;

  root = state(0, 0, j, y, "");

  trace(root, str);

  freetree(root);

  return 0;
}

Error: -11

Fixed submission:

//
//  0285.cpp
//
//
//  Created by Minote Tomoki on 2015/06/01.
//
//

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>

typedef struct _tree {
  std::string val;
  struct _tree *left;
  struct _tree *right;
} node;

int offset = 0;

node *state(int j, int i, int tj, int ty, std::string output) {
  node *r;

  r = (node *)malloc(sizeof(node));
  r->val = output;
  r->left = NULL;
  r->right = NULL;

  if (j == tj && ty == i)
    return r;

  if ((i <= 3 && j == 5) || (i == 5 && j <= 3)) {
    return NULL;
  } else if ((i > 4 && j > 4) && (i - j) * (i - j) > 4) {
    return NULL;
  }

  if (j < tj)
    r->left = state(j + 1, i, tj, ty, "A");
  if (i < ty)
    r->right = state(j, i + 1, tj, ty, "B");
  return r;
}

void trace(node *r, std::string str) {
  str += (r->val);

  if (r->left == NULL && r->right == NULL) {
    std::cout << str << std::endl;
  }

  if (r->left != NULL)
    trace(r->left, str);
  if (r->right != NULL)
    trace(r->right, str);
}

void freetree(node *n) {
  if (n->left != NULL)
    freetree(n->left);
  if (n->right != NULL)
    freetree(n->right);
  free(n);
}

int main(void) {
  int j;
  int y;

  std::string str{};

  node *root = NULL;

  scanf("%d %d", &j, &y);
  if (j == 0 && y == 0)
    return 0;

  root = state(0, 0, j, y, "");

  trace(root, str);

  freetree(root);

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

#include <iostream>
#include <vector>
using namespace std;
int b[10001];
vector<vector<pair<int, int>>> a;
int main() {
  int n, m;
  cin >> n >> m;
  a.resize(n + 1);
  int s, t, e;
  while (cin >> s >> t >> e && (s || t || e)) {
    a[s].push_back(make_pair(t, e));
  }
  int L;
  cin >> L;
  for (int k = 0; k < L; k++) {
    for (int i = 1; i <= m; i++)
      cin >> b[i];
    for (int i = 1; i <= n; i++) {
      int sumab = 0;
      for (int j = 0; j < a[i].size(); j++)
        sumab += a[i][j].second * b[a[i][j].first];
      cout << sumab;
      if (i == n)
        cout << endl;
      else
        cout << " ";
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;
int b[10001];
int a[10001][10001] = {};
int main() {
  int n, m;
  cin >> n >> m;
  int s, t, e;
  while (cin >> s >> t >> e && (s || t || e))
    a[s][t] = e;
  int L;
  cin >> L;
  for (int k = 0; k < L; k++) {
    for (int i = 1; i <= m; i++)
      cin >> b[i];
    for (int i = 1; i <= n; i++) {
      int sumab = 0;
      for (int j = 1; j <= m; j++)
        sumab += a[i][j] * b[j];
      cout << sumab;
      if (i == n)
        cout << endl;
      else
        cout << " ";
    }
  }

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

#include <algorithm>
#include <stdio.h>
using namespace std;
int s[51000];
int t[51000];
int e[51000];
int d[11000];
long long ret[11000];
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int p, q, r;
  int sz = 0;
  while (scanf("%d%d%d", &p, &q, &r), p) {
    p--;
    q--;
    s[sz] = p;
    t[sz] = q;
    e[sz++] = r;
  }
  int c;
  scanf("%d", &c);
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < b; j++)
      scanf("%d", d + j);
    for (int j = 0; j < a; j++)
      ret[j] = 0LL;
    for (int j = 0; j < sz; j++)
      ret[s[j]] += d[t[j]] * e[j];
    for (int j = 0; j < a; j++) {
      if (j)
        printf(" ");
      printf("%lld", ret[j]);
    }
    printf("\\n");
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int s[11000];
int t[11000];
int e[11000];
int d[11000];
long long ret[11000];
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int p, q, r;
  int sz = 0;
  while (scanf("%d%d%d", &p, &q, &r), p) {
    p--;
    q--;
    s[sz] = p;
    t[sz] = q;
    e[sz++] = r;
  }
  int c;
  scanf("%d", &c);
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < b; j++)
      scanf("%d", d + j);
    for (int j = 0; j < a; j++)
      ret[j] = 0LL;
    for (int j = 0; j < sz; j++)
      ret[s[j]] += d[t[j]] * e[j];
    for (int j = 0; j < a; j++) {
      if (j)
        printf(" ");
      printf("%lld", ret[j]);
    }
    printf("\\n");
  }
}
Problem p00281 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

// int nm[10001][10001] = {0};

map<pair<int, int>, int> nm;

long long c[10001];

int b[10000];

int main() {
  int n, m;

  cin >> n >> m;

  while (1) {
    int s, t, e;
    scanf(" %d %d %d", &s, &t, &e);
    if ((s + t + e) == 0)
      break;
    // nm[s][t] = e;
    nm[make_pair(s, t)] = e;
  }

  int l;

  cin >> l;

  pair<int, int> tmp;

  while (l--) {

    for (int i = 1; i <= m; i++) {
      scanf(" %d", &b[i]);
    }

    int i, j;
    for (i = 1; i <= n; i++) {
      c[i] = 0;
      /*for (j = 0; j < m; j++) {
          c[i] = c[i] + nm[i][j+1] * b[j];
      }*/
    }
    for (map<pair<int, int>, int>::iterator itr = nm.begin(); itr != nm.end();
         ++itr) {
      tmp = itr->first;
      c[tmp.first] += b[tmp.second] * itr->second;
      // cout << "I'm hungry " << c[tmp.first] << " " << tmp.first << " " <<
      // tmp.second << endl;
    }

    for (int i = 1; i <= n; i++) {
      cout << c[i];
      if (i != n)
        cout << ' ';
    }
    cout << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

int nm[10001][10001] = {0};

long long c[10001];

int b[10000];

int main() {
  int n, m;

  cin >> n >> m;

  while (1) {
    int s, t, e;
    scanf(" %d %d %d", &s, &t, &e);
    if ((s + t + e) == 0)
      break;
    nm[s][t] = e;
  }

  int l;

  cin >> l;

  while (l--) {

    for (int i = 0; i < m; i++) {
      scanf(" %d", &b[i]);
    }

    int i, j;
    for (i = 1; i <= n; i++) {
      c[i] = 0;
      for (j = 0; j < m; j++) {
        c[i] = c[i] + nm[i][j + 1] * b[j];
      }
    }

    for (int i = 1; i <= n; i++) {
      cout << c[i];
      if (i != n)
        cout << ' ';
    }
    cout << endl;
  }
  return 0;
}
Problem p00281 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int c[10010][10010], n, m, l, b[101][10010];

typedef pair<int, int> P;

int main() {
  cin >> n >> m;
  vector<P> vec[10010];
  while (1) {
    int s, t, e;
    cin >> s >> t >> e;
    if (s == 0)
      break;
    vec[s - 1].push_back(P(t - 1, e));
  }
  cin >> l;
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < n; j++) {
      int ans = 0;
      for (P p : vec[j]) {
        ans += b[i][p.first] * p.second;
      }
      cout << (j ? " " : "") << ans;
    }
    cout << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int d[10010][10010], c[10010][10010], n, m, l, b[10010][10010];

int main() {
  cin >> n >> m;
  while (1) {
    int s, t, e;
    cin >> s >> t >> e;
    if (s == 0)
      break;
    d[s - 1][t - 1] = e;
  }
  cin >> l;
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        c[i][j] += d[j][k] * b[i][k];
      }
    }
  }
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < n; j++) {
      cout << (j ? " " : "") << c[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p00281 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <unordered_map>
#include <vector>
#define P pair<int, int> //?¨????  ?????°
using namespace std;

vector<P> d[10000];
int k[10000];
int main() {
  int n, m;
  cin >> n >> m;
  int a, b, c;
  while (scanf("%d%d%d", &a, &b, &c), (a | b) || c) {
    a--;
    b--;
    d[a].push_back(P(b, c));
  }
  cin >> a;
  for (b = 0; b < a; b++) {
    for (int i = 0; i < m; i++)
      scanf("%d", &k[i]);
    for (int i = 0; i < n; i++) {
      if (i)
        cout << " ";
      int q = 0;
      for (P s : d[i]) {
        q += k[s.first] * s.second;
      }
      cout << q;
    }
    cout << endl;
  }
}

Error: MLE

Fixed submission:

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

int a[10000][10000];
int main() { memset(a, 0, sizeof(a)); }
Problem p00281 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
using namespace std;
long long s[50001], t[50001], e[50001];
long long b[10001], ans[10001];
int main() {
  int n, m, top = 0;
  cin >> n >> m;
  while (true) {
    cin >> s[top] >> t[top] >> e[top];
    if (s[top] == 0 && t[top] == 0 && e[top] == 0)
      break;
    top++;
  }
  int v;
  cin >> v;
  for (int u = 0; u < v; u++) {
    for (int i = 0; i < n; i++)
      ans[i] = 0;
    for (int i = 0; i < m; i++)
      cin >> b[i];
    for (int set = 0; set < top; set++)
      ans[s[set] - 1] += b[t[set] - 1] * e[set];
    cout << ans[0];
    for (int i = 1; i < n; i++)
      cout << " " << ans[i];
    cout << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;
int mem[10000][10000], b[10000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      mem[i][j] = 0;
  int s, t, e;
  while (true) {
    cin >> s >> t >> e;
    if (s == 0 && t == 0 && e == 0)
      break;
    mem[s - 1][t - 1] += e;
  }
  int l;
  cin >> l;
  for (int u = 0; u < l; u++) {
    for (int i = 0; i < m; i++)
      cin >> b[i];
    for (int i = 0; i < n; i++) {
      long long ans = 0;
      for (int j = 0; j < m; j++)
        ans += mem[i][j] * b[j];
      if (i != 0)
        cout << " ";
      cout << ans;
    }
    cout << endl;
  }
  return 0;
}
Problem p00281 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

struct Work {
  int s, t, e;
};

int main() {
  int N, M;
  cin >> N >> M;

  int s, t, e;
  vector<Work> work;
  while (cin >> s >> t >> e, s | t | e)
    work.push_back({s - 1, t - 1, e});

  int L;
  cin >> L;
  for (int l = 0; l < L; ++l) {
    vector<int> b(M);
    for (auto &i : b)
      cin >> i;
    vector<int> c(N, 0);
    for (const auto &w : work)
      c[w.s] += b[w.t] * w.e;

    for (int i = 0; i < N; ++i)
      cout << (i == 0 ? "" : " ") << c[i];
    cout << endl;
  }
}

Error: MLE

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;

  int s, t, e;
  vector<vector<int>> a(N, vector<int>(M, 0));
  while (cin >> s >> t >> e, s | t | e)
    a[s - 1][t - 1] += e;

  int L;
  cin >> L;
  for (int l = 0; l < L; ++l) {
    vector<int> b(M);
    for (auto &i : b)
      cin >> i;
    vector<int> c(N, 0);
    for (int i = 0; i < N; ++i)
      for (int j = 0; j < M; ++j)
        c[i] += a[i][j] * b[j];

    for (int i = 0; i < N; ++i)
      cout << (i == 0 ? "" : " ") << c[i];
    cout << endl;
  }
}
Problem p00281 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int n, m;
vector<P> v[10000];
int r[10000];

int main() {
  scanf("%d %d", &n, &m);
  while (true) {
    int s, t, e;
    scanf("%d %d %d", &s, &t, &e);
    if (!s)
      break;
    v[--t].push_back(P(--s, e));
  }

  int L;
  scanf("%d", &L);
  for (int ca = 0; ca < L; ca++) {
    memset(r, 0, sizeof(r));
    for (int i = 0; i < m; i++) {
      int b;
      scanf("%d", &b);
      for (int j = 0; j < v[i].size(); j++) {
        r[v[i][j].first] += v[i][j].second * b;
      }
    }
    for (int i = 0; i < n; i++) {
      if (i)
        printf(" ");
      printf("%d", r[i]);
    }
    puts("");
  }
}

Error: MLE

Fixed submission:

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

int n, m;
short a[10000][10000];
int r[10000];

int main() {
  scanf("%d %d", &n, &m);
  while (true) {
    int s, t, e;
    scanf("%d %d %d", &s, &t, &e);
    if (!s)
      break;
    a[--s][--t] += e;
  }

  int L;
  scanf("%d", &L);
  for (int ca = 0; ca < L; ca++) {
    memset(r, 0, sizeof(r));
    for (int i = 0; i < m; i++) {
      int c;
      scanf("%d", &c);
      for (int j = 0; j < n; j++) {
        r[j] += c * a[j][i];
      }
    }
    for (int i = 0; i < n; i++) {
      if (i)
        printf(" ");
      printf("%d", r[i]);
    }
    puts("");
  }
}
Problem p00281 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define FOR(v, a, b) for (int v = (a); v < (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define UNWORDS(vec, str)                                                      \\
  for (int i = 0; i < (vec).size(); ++i)                                       \\
  cout << (i ? str : "") << (vec)[i]
#define UNLINES(vec)                                                           \\
  for (int i = 0; i < (vec).size(); ++i)                                       \\
  cout << (vec)[i] << endl
#define RS resize
#define CLR clear
#define PB push_back
using namespace std;

int main() {
  int n, m, s, t, e, l;
  vector<map<int, int>> a;
  vector<int> b, c;

  cin >> n >> m;
  b.RS(m);
  a.RS(n);
  c.RS(n);

  while (cin >> s >> t >> e, s) {
    a[s - 1][t - 1] = e;
  }

  cin >> l;

  REP(i, l) {

    REP(j, m) cin >> b[j];

    REP(j, n) {
      c[j] = 0;

      for (map<int, int>::iterator it = a[j].begin(); it != a[j].end(); ++it) {
        c[j] += (it->second) * b[it->first];
      }
    }

    UNWORDS(c, " ");
    cout << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(v, a, b) for (int v = (a); v < (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define UNWORDS(vec, str)                                                      \\
  for (int i = 0; i < (vec).size(); ++i)                                       \\
  cout << (i ? str : "") << (vec)[i]
#define UNLINES(vec)                                                           \\
  for (int i = 0; i < (vec).size(); ++i)                                       \\
  cout << (vec)[i] << endl
#define RS resize
#define CLR clear
#define PB push_back
using namespace std;

int main() {
  int n, m, s, t, e, l;
  vector<vector<int>> a;
  vector<int> b, c;

  cin >> n >> m;
  b.RS(m);
  a.RS(n);
  c.RS(n);
  REP(i, n) a[i].RS(m);

  while (cin >> s >> t >> e, s) {
    a[s - 1][t - 1] = e;
  }

  cin >> l;

  REP(i, l) {

    REP(j, m) cin >> b[j];

    REP(j, n) {
      c[j] = 0;
      REP(k, m) { c[j] += a[j][k] * b[k]; }
    }

    UNWORDS(c, " ");
    cout << endl;
  }

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

#include <iostream>
#include <vector>

using namespace std;

struct Edge {
  int kindOfTask;
  int runNum;
};

void solve() {
  int N, M;
  cin >> N >> M;
  vector<Edge> a[50001];
  int s, t, e;
  while (cin >> s >> t >> e, s || t || e) {
    Edge edge;
    edge.kindOfTask = --t;
    edge.runNum = e;
    a[--s].push_back(edge);
  }
  int L;
  cin >> L;
  for (int i = 0; i < L; ++i) {
    vector<int> c(M);
    for (int j = 0; j < M; ++j) {
      cin >> c[j];
    }
    bool isFirst = true;
    for (int j = 0; j < N; ++j) {
      int salary = 0;
      for (int k = 0; k < a[j].size(); ++k) {
        Edge edge = a[j][k];
        salary += edge.runNum * c[edge.kindOfTask];
      }
      if (!isFirst) {
        cout << " ";
      }
      isFirst = false;
      cout << salary;
    }
    cout << endl;
  }
}

int main() {
  solve();
  return (0);
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

void solve() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> a(N, vector<int>(M));
  int s, t, e;
  while (cin >> s >> t >> e, s || t || e) {
    a[--s][--t] = e;
  }
  int L;
  cin >> L;
  for (int i = 0; i < L; ++i) {
    vector<int> c(M);
    for (int j = 0; j < M; ++j) {
      cin >> c[j];
    }
    bool isFirst = true;
    for (int j = 0; j < N; ++j) {
      int salary = 0;
      for (int k = 0; k < M; ++k) {
        salary += a[j][k] * c[k];
      }
      if (!isFirst) {
        cout << " ";
      }
      isFirst = false;
      cout << salary;
    }
    cout << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p00281 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

map<int, vector<P>> mp;

int main() {
  int n, m;
  cin >> n >> m;

  while (1) {
    int a, b, c;
    cin >> a >> b >> c;
    if (!a)
      break;
    mp[a].pb(P(b, c));
  }

  int l;
  cin >> l;
  rep(i, 0, l) {
    int h[10001] = {};
    rep(j, 1, m + 1) cin >> h[j];
    rep(j, 1, n + 1) {
      int kyu = 0;
      rep(k, 0, mp[j].size()) { kyu += h[mp[j][k].first] * mp[j][k].second; }
      cout << kyu;
      if (j == n)
        cout << endl;
      else
        cout << " ";
    }
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int v[10001][10001] = {};

int main() {
  ll n, m, l;
  cin >> n >> m;
  ll a, b, c;
  while (cin >> a >> b >> c) {
    if (!a)
      break;
    v[a][b] = c;
  }

  cin >> l;
  for (int i = 0; i < l; i++) {
    ll s[10001] = {};
    for (int j = 1; j <= m; j++)
      cin >> s[j];
    for (int j = 1; j <= n; j++) {
      ll sum = 0;
      for (int k = 1; k <= m; k++) {
        sum += v[j][k] * s[k];
      }
      cout << sum;
      if (j == n)
        cout << endl;
      else
        cout << " ";
    }
  }
}