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

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int D[523][523];
int g[523][523];
int cnt, fx, fy;

void find(int y, int x) {
  if (D[y][x]) {
    fy = y + 1;
    fx = x + 1;
    cnt++;
    int p = D[y][x];
    g[fy][fx] = p;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        D[y + i][x + j] -= p;
      }
    }
  }
}

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> D[i][j];
    }
  }
  for (int i = 0; i < W; i++) {
    int y = 0, x = i;
    for (; x >= 0; y++, x--) {
      find(y, x);
    }
  }
  for (int i = 1; i < H; i++) {
    int y = i, x = W - 1;
    for (; y < H; y++, x--) {
      find(y, x);
    }
  }
  vector<pair<int, int>> ans;
  if (cnt == 1) {
    ans.emplace_back(fy, fx);
  } else {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (g[i][j]) {
          int d = g[i][j] - 1;
          for (int k = -1; k <= 1; k++) {
            int ny = i + k;
            if (ny < 0 || H <= ny)
              continue;
            for (int l = -1; l <= 1; l++) {
              int nx = j + l;
              if (nx < 0 || W <= nx || k == 0 && l == 0)
                continue;
              d += g[ny][nx];
            }
          }
          if (d % 2) {
            ans.emplace_back(i, j);
          }
        }
      }
    }
  }
  cout << ans.back().first << ' ' << ans.back().second << ' ' << ans[0].first
       << ' ' << ans[0].second << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int D[523][523];
int g[523][523];
int cnt, fx, fy;

void find(int y, int x) {
  if (D[y][x]) {
    fy = y + 1;
    fx = x + 1;
    cnt += D[y][x];
    int p = D[y][x];
    g[fy][fx] = p;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        D[y + i][x + j] -= p;
      }
    }
  }
}

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> D[i][j];
    }
  }
  for (int i = 0; i < W; i++) {
    int y = 0, x = i;
    for (; x >= 0; y++, x--) {
      find(y, x);
    }
  }
  for (int i = 1; i < H; i++) {
    int y = i, x = W - 1;
    for (; y < H; y++, x--) {
      find(y, x);
    }
  }
  vector<pair<int, int>> ans;
  if (cnt == 1) {
    ans.emplace_back(fy, fx);
  } else {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (g[i][j]) {
          int d = g[i][j] - 1;
          for (int k = -1; k <= 1; k++) {
            int ny = i + k;
            if (ny < 0 || H <= ny)
              continue;
            for (int l = -1; l <= 1; l++) {
              int nx = j + l;
              if (nx < 0 || W <= nx || k == 0 && l == 0)
                continue;
              d += g[ny][nx];
            }
          }
          if (d % 2) {
            ans.emplace_back(i, j);
          }
        }
      }
    }
  }
  cout << ans.back().first << ' ' << ans.back().second << ' ' << ans[0].first
       << ' ' << ans[0].second << endl;
}
Problem p01857 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = 1; i < n; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \\
  REP(i, v.size()) cout << #v << "[" << i << "]: " << v[i] << endl
#define ALL(a) (a).begin(), (a).end()

ll eggdrops[51][51];

int main() {
  // https://oeis.org/A180975
  REP(i, 51) REP(j, 51) {
    if (i == 0 || j == 0)
      eggdrops[i][j] = 0;
    else
      eggdrops[i][j] = eggdrops[i - 1][j - 1] + 1 + eggdrops[i - 1][j];
  }

  int T;
  cin >> T;
  REP(_t, T) {
    ll N, E;
    cin >> N >> E;
    REP(n, 51) {
      ll w = eggdrops[n][E];
      if (N <= w) {
        cout << n << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = 1; i < n; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \\
  REP(i, v.size()) cout << #v << "[" << i << "]: " << v[i] << endl
#define ALL(a) (a).begin(), (a).end()
#define INF 1e9;

ll bin[51];

int dfs(ll width, ll eggs, int nowcnt) {
  if (nowcnt > 50)
    return INF; // ????????¶????????????????????????
  if (width == 0)
    return 0; // ???0????????????????????£??????
  if (eggs == 0)
    return INF; // ??????
  if (width == 1)
    return 1; // ???1??????1????????¨????????????
  if (eggs == 1)
    return width; // ???1????????°???????????¨???
  if (width > bin[50 - nowcnt])
    return INF; // ??????????????????50???2?????¢?´¢???????????????????????????
  ll mid = width / 2;
  ++mid;
  int result = INF;
  int ka = 0;
  for (int i = mid; mid >= 0; --mid) {
    int cnt =
        dfs(i - 1, eggs, nowcnt + 1) + dfs(width - i, eggs - 1, nowcnt + 1);
    if (cnt <= result)
      result = cnt;
    else {
      ++ka;
      if (ka > 5)
        break;
    }
  }
  return result;
}

int main() {
  bin[0] = 1;
  REPR(i, 51) bin[i] = bin[i - 1] * 2;
  int T;
  cin >> T;
  REP(_t, T) {
    ll N, E;
    cin >> N >> E;
    ll result = dfs(N, E, 0);
    cout << result << endl;
  }
  return 0;
}
Problem p01861 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()

struct Rule {
  int num;
  int l;
  int r;
};
int memo[10][100][100];
vector<Rule> Rules;
int start;
vector<int> Retu;

bool dp(int kisoku, int l, int r) {
  if (memo[kisoku][l][r] != -1) {
    return memo[kisoku][l][r];
  }
  if (l == r) {
    memo[kisoku][l][r] = (Rules[kisoku].num == Retu[l]);
    return memo[kisoku][l][r];
  } else {
    for (int i = l; i < r; ++i) {
      if (dp(Rules[kisoku].l - 1, l, i) && dp(Rules[kisoku].r - 1, i + 1, r)) {
        memo[kisoku][l][r] = true;
        return true;
      } else {
      }
    }
  }
  memo[kisoku][l][r] = false;
  return false;
}
int main() {
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 100; ++j) {
      for (int k = 0; k < 100; ++k) {
        memo[i][j][k] = -1;
      }
    }
  }
  int N;
  cin >> N;
  rep(i, N) {
    int x;
    cin >> x;
    Retu.push_back(x);
  }
  int M;
  cin >> M;

  rep(i, M) {
    int kisoku, l, r;
    cin >> kisoku >> l >> r;
    Rules.push_back({kisoku, l, r});
  }
  start = Rules[0].num;
  if (dp(0, 0, N - 1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()

struct Rule {
  int num;
  int l;
  int r;
};

vector<Rule> Rules;
int start;
vector<int> Retu;

bool dp(int kisoku, int l, int r) {
  if (l == r) {
    return Rules[kisoku].num == Retu[l];
  } else {
    for (int i = l; i < r; ++i) {
      if (dp(Rules[kisoku].l - 1, l, i) && dp(Rules[kisoku].r - 1, i + 1, r)) {
        return true;
      } else {
      }
    }
  }
  return false;
}
int main() {

  int N;
  cin >> N;
  rep(i, N) {
    int x;
    cin >> x;
    Retu.push_back(x);
  }
  int M;
  cin >> M;

  rep(i, M) {
    int kisoku, l, r;
    cin >> kisoku >> l >> r;
    Rules.push_back({kisoku, l, r});
  }
  start = Rules[0].num;
  if (dp(0, 0, N - 1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

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

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

void z_algorithm(string &S, vector<int> &A) {
  int sz = (int)S.size();
  A.resize(sz);
  A[0] = S.size();
  int i = 1, j = 0;
  while (i < S.size()) {
    while (i + j < S.size() && S[j] == S[i + j])
      ++j;
    A[i] = j;
    if (j == 0) {
      ++i;
      continue;
    }
    int k = 1;
    while (i + k < S.size() && k + A[k] < j)
      A[i + k] = A[k], ++k;
    i += k;
    j -= k;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a, b;
  z_algorithm(s, a);

  reverse(s.begin(), s.end());
  z_algorithm(s, b);
  int ma = -1;
  for (int i = n / 3 - 2; i < n / 2 + 2; i++) {
    if (i <= 0 || i >= n)
      continue;
    int tmp = n - 2 * i;
    if (a[i] == n - i && b[i] == n - i && tmp > 0 && (n - 3 * (tmp)) / 2 > 0 &&
        (n - 3 * (tmp)) % 2 == 0) {
      ma = max(ma, tmp);
    }
  }
  // for(int i=0;i<n;i++){
  //     cout << a[i] << " ";
  // }
  // cout << endl;
  // for(int i=0;i<n;i++){
  //     cout << b[i] << " ";
  // }
  // cout << endl;

  if (ma == -1) {
    cout << "mitomerarenaiWA" << endl;
  } else {
    int x = ma;
    int y = (n - 3 * ma) / 2;
    printf("Love ");
    for (int i = 0; i < x + y; i++) {
      printf("%c", s[n - i - 1]);
    }
    printf("!\\n");
    // cout << x << " " << y << " " << n << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

void z_algorithm(string &S, vector<int> &res) {
  int sz = (int)S.size();
  res.resize(sz);
  int c = 0;
  for (int i = 1; i < sz; i++) {
    if (i + res[i - c] < c + res[c]) {
      res[i] = res[i - c];
    } else {
      int j = max(0, c + res[c] - i);
      while (i + j < sz && S[j] == S[i + j])
        ++j;
      res[i] = j;
    }
  }
  res[0] = sz;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a, b;
  z_algorithm(s, a);
  reverse(s.begin(), s.end());
  z_algorithm(s, b);
  int ma = -1;
  for (int i = n / 3 - 2; i < n / 2 + 2; i++) {
    if (i <= 0 || i >= n)
      continue;
    int tmp = n - 2 * i;
    if (a[i] == n - i && b[i] == n - i && tmp > 0 && (n - 3 * (tmp)) / 2 > 0 &&
        (n - 3 * (tmp)) % 2 == 0) {
      ma = max(ma, tmp);
    }
  }
  // for(int i=0;i<n;i++){
  //     cout << a[i] << " ";
  // }
  // cout << endl;
  // for(int i=0;i<n;i++){
  //     cout << b[i] << " ";
  // }
  // cout << endl;

  if (ma == -1) {
    cout << "mitomerarenaiWA" << endl;
  } else {
    int x = ma;
    int y = (n - 3 * ma) / 2;
    printf("Love ");
    for (int i = 0; i < x + y; i++) {
      printf("%c", s[n - i - 1]);
    }
    printf("!\\n");
  }
  return 0;
}
Problem p01865 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int L, N, W[100] = {};
  cin >> L >> N;
  for (int i = 0; i < N; i++) {
    int x, w;
    cin >> x >> w;
    W[x + 50] += w;
  }

  vector<pair<int, int>> ret;
  for (int i = -L; i < 0; i++) {
    int P = W[50 + i];
    int Q = W[50 - i];
    int R = max(W[50 + i], W[50 - i]);
    for (int j = W[50 + i]; j < R; j++) {
      ret.push_back({i, 1});
    }
    for (int j = W[50 - i]; j < R; j++) {
      ret.push_back({-i, 1});
    }
  }
  cout << ret.size() << endl;
  for (auto k : ret) {
    cout << k.first << " " << k.second << endl;
  }
}

Error: WA

Fixed submission:

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

int main() {
  int L, N, W[100] = {};
  cin >> L >> N;
  for (int i = 0; i < N; i++) {
    int x, w;
    cin >> x >> w;
    W[x + 50] += w;
  }

  vector<pair<int, int>> ret;
  for (int i = -2 * L; i < 0; i++) {
    int P = W[50 + i];
    int Q = W[50 - i];
    int R = max(W[50 + i], W[50 - i]);
    for (int j = W[50 + i]; j < R; j++) {
      ret.push_back({i, 1});
    }
    for (int j = W[50 - i]; j < R; j++) {
      ret.push_back({-i, 1});
    }
  }
  cout << ret.size() << endl;
  for (auto k : ret) {
    cout << k.first << " " << k.second << endl;
  }
}
Problem p01866 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <cstdio>
#include <vector>
using namespace std;

int n;
int d;
char S[1001];
vector<int> ones;

int main() {
  scanf("%d", &n);
  scanf("%s", S);
  scanf("%d", &d);

  for (int i = 0; i < n && d > 0; i++) {
    if (S[i] == '1')
      ones.push_back(i);
    else if (S[i] == '0') {
      S[i] = '1';
      --d;
    }
  }

  while (d > 0) {
    int idx = ones.back();
    assert(S[idx] == '1');
    S[idx] = '0';
    d--;
    ones.pop_back();
  }

  puts(S);
}

Error: 0

Fixed submission:

#include <cassert>
#include <cstdio>
#include <vector>
using namespace std;

int n;
int d;
char S[1001];
vector<int> ones;

int main() {
  scanf("%d", &n);
  scanf("%s", S);
  scanf("%d", &d);

  for (int i = 0; i < n && d > 0; i++) {
    if (S[i] == '1')
      ones.push_back(i);
    else if (S[i] == '0') {
      S[i] = '1';
      --d;
    }
  }

  while (d > 0) {
    int idx = ones.back();
    assert(S[idx] == '1');
    S[idx] = '0';
    d--;
  }

  puts(S);
}
Problem p01867 (C++) — buggy submission, verdict: Runtime Error

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

int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n >> s;

  int a[30] = {};
  for (int i = 0; i < n; i += 2) {
    ++a[s[i] - 'a'];
  }
  sort(a, a + 30);
  reverse(a, a + 30);
  int ans = 0, now = -1, cnt = 0;
  for (int i = 0; i < 30;) {
    if (a[i] == 0)
      break;
    else if (a[i] == 1)
      ans += 2, ++i;
    else {
      now = a[i];
      while (now == a[i])
        ++cnt, ++i;
      if (cnt > 2)
        ans += 8 + (cnt - 2) * 2;
      else
        ans += 4 * cnt;
      cnt = 0;
    }
  }
  cout << ans - 1 << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n >> s;

  int a[30] = {};
  for (int i = 0; i < n; i += 2) {
    ++a[s[i] - 'a'];
  }
  sort(a, a + n);
  reverse(a, a + n);
  int ans = 0, now = -1, cnt = 0;
  for (int i = 0; i < 30;) {
    if (a[i] == 0)
      break;
    else if (a[i] == 1)
      ans += 2, i++;
    else {
      now = a[i];
      while (now == a[i])
        ++cnt, ++i;
      if (cnt > 2)
        ans += 8 + (cnt - 2) * 2;
      else
        ans += 4 * cnt;
      cnt = 0;
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
Problem p01867 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, j) for (int i = 0; i < (j); i++)

int num_len(int n) {
  int res = 0;
  while (n) {
    n /= 10;
    res++;
  }
  return res;
}

int count(vector<char> &cs, int cnt) {
  if (cs.size() == 0 or cnt == 0)
    return 0;

  if (cs.size() == 1) {
    if (cnt > 1)
      return 3;
    else
      return 1;
  } else if (cnt > 1) {
    return cs.size() * 2 - 1 + 2 + num_len(cnt) + 1;
  } else {
    return cs.size() * 2 - 1;
  }
}

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  vector<int> c_cnt('z' - 'a' + 1, 0);
  for (char c : s) {
    if ('a' <= c and c <= 'z')
      c_cnt[c - 'a']++;
  }
  map<int, vector<char>> i_cnt;
  rep(i, c_cnt.size()) {
    if (c_cnt[i] > 0) {
      i_cnt[c_cnt[i]].push_back(i + 'a');
    }
  }
  bool flg = false;
  int ans = 0;
  for (auto &p : i_cnt) {
    int cnt = p.first;
    vector<char> cs = p.second;
    // cerr << cnt << " " ;
    // rep(j, cs.size()) cerr << cs[j] << " ";
    // cerr << endl;
    if (flg) {
      ans++;
    }
    flg = true;
    ans += count(cs, cnt);
  }
  cout << ans << endl;
  return 0;
}

Error: 0
3 a 


Fixed submission:

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

#define rep(i, j) for (int i = 0; i < (j); i++)

int num_len(int n) {
  int res = 0;
  while (n) {
    n /= 10;
    res++;
  }
  return res;
}

int count(vector<char> &cs, int cnt) {
  if (cs.size() == 1) {
    if (cnt > 1)
      return 3;
    else
      return 1;
  } else if (cnt > 1) {
    return cs.size() * 2 - 1 + 2 + num_len(cnt) + 1;
  } else {
    return cs.size() * 2 - 1;
  }
}

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  vector<int> c_cnt('z' - 'a' + 1, 0);
  for (char c : s) {
    if ('a' <= c and c <= 'z')
      c_cnt[c - 'a']++;
  }
  map<int, vector<char>> i_cnt;
  rep(i, c_cnt.size()) {
    if (c_cnt[i] > 0) {
      i_cnt[c_cnt[i]].push_back(i + 'a');
    }
  }
  bool flg = false;
  int ans = 0;
  for (auto p : i_cnt) {
    int cnt = p.first;
    vector<char> cs = p.second;
    cerr << cnt << " ";
    rep(j, cs.size()) cerr << cs[j] << " ";
    cerr << endl;
    if (flg) {
      ans++;
    }
    flg = true;
    ans += count(cs, cnt);
  }
  cout << ans << endl;
  return 0;
}
Problem p01867 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string S;
int a[26], n;
vector<int> p;
int main() {
  cin >> n >> S;
  for (int i = 0; i < S.size(); i += 2) {
    a[S[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (a[i] >= 1)
      p.push_back(a[i]);
  }
  sort(p.begin(), p.end());
  int cnt = 0;
  while (p.size() >= 1) {
    int i = p.size() - 1;
    int F = 0;
    for (int j = i; j >= 0; j--) {
      if (p[j] != p[i]) {
        F = j + 1;
        break;
      }
    }
    if (p[i] != 1) {
      cnt += 2;
      if (i != F)
        cnt += 2;
    }
    for (int j = i; j >= F; j--) {
      p[j] -= min(9, p[j]);
      cnt += 2;
    }
    sort(p.begin(), p.end());
    while (p.size() >= 1 && p[p.size() - 1] == 0)
      p.pop_back();
  }
  cout << cnt - 1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string S;
int a[26], n;
vector<int> p;
int solve(vector<int> vec) {
  if (vec.size() == 0)
    return 0;
  int maxn = 100000;
  for (int i = 0; i < vec.size(); i++) {
    int H = vec[0];
    vector<int> vec1 = vec;
    for (int j = 0; j <= i; j++)
      vec1[j] -= H;
    int Len = 0;
    if (H >= 2)
      Len += to_string(H).size() + 1;
    if (i >= 1)
      Len += i * 2 + 3;
    if (i == 0)
      Len += 1;

    vector<int> vec2;
    for (int i = 0; i < vec1.size(); i++) {
      if (vec1[i] >= 1)
        vec2.push_back(vec1[i]);
    }
    maxn = min(maxn, solve(vec2) + Len + 1);
  }
  return maxn;
}
int main() {
  cin >> n >> S;
  for (int i = 0; i < S.size(); i += 2) {
    a[S[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (a[i] >= 1)
      p.push_back(a[i]);
  }
  sort(p.begin(), p.end());
  cout << solve(p) - 1 << endl;
  return 0;
}
Problem p01868 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, j) for (int i = 0; i < (j); i++)
using namespace std;

bool visit[51][2501][2501] = {};

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int allsum = 0;
  rep(i, n) {
    cin >> t[i];
    allsum += t[i];
  }
  int ans = 1 << 30;
  visit[0][0][0] = true;
  rep(i, n) {
    rep(j, allsum) {
      rep(k, allsum) {
        if (visit[i][j][k] and j + t[i] <= allsum and k + t[i] <= allsum) {
          visit[i + 1][j + t[i]][k] = true;
          visit[i + 1][j][k + t[i]] = true;
          visit[i + 1][j][k] = true;
        }
      }
    }
  }
  rep(j, allsum) {
    rep(k, allsum) {
      if (visit[n][j][k])
        ans = min(ans, max({j, k, allsum - j - k}));
    }
  }

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

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, j) for (int i = 0; i < (j); i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int allsum = 0;
  rep(i, n) {
    cin >> t[i];
    allsum += t[i];
  }
  bool visit[51][2500][2500] = {};
  int ans = 1 << 30;
  rep(i, n) {
    rep(j, allsum) {
      rep(k, allsum) {
        if (visit[i][j][k]) {
          visit[i + 1][j + t[i]][k] = true;
          visit[i + 1][j][k + t[i]] = true;
          visit[i + 1][j][k] = true;
        }
      }
    }
  }
  rep(j, allsum) {
    rep(k, allsum) {
      if (visit[n][j][k])
        ans = min(ans, max({j, k, allsum - j - k}));
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p01868 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define INF 1000000000

int memo[50][860][860];
int N;
int sum = 0;
vector<int> t;

int dfs(int i, int x, int y) {
  if (i == N) {
    int z = sum - x - y;
    return max({x, y, z});
  }
  if (memo[i][x][y] >= 0)
    return memo[i][x][y];
  int ans = INF;
  if (x + t[i] < 860)
    ans = min(ans, dfs(i + 1, x + t[i], y));
  if (y + t[i] < 860)
    ans = min(ans, dfs(i + 1, x, y + t[i]));
  ans = min(ans, dfs(i + 1, x, y));
  memo[i][x][y] = ans;
  return ans;
}

int main(void) {
  memset(memo, -1, sizeof(memo));
  cin >> N;
  t.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> t[i];
    sum += t[i];
  }
  cout << dfs(0, 0, 0) << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define INF 1000000000

int memo[50][860][860];
int N;
int sum = 0;
vector<int> t;

void set_memo() {
  for (int i = 0; i < 50; ++i) {
    for (int j = 0; j < 860; ++j) {
      for (int k = 0; k < 860; ++k) {
        memo[i][j][k] = -1;
      }
    }
  }
}

int dfs(int i, int x, int y) {
  if (i == N) {
    int z = sum - x - y;
    return max({x, y, z});
  }
  if (memo[i][x][y] >= 0)
    return memo[i][x][y];
  int ans = INF;
  if (x + t[i] <= 860)
    ans = min(ans, dfs(i + 1, x + t[i], y));
  if (y + t[i] <= 860)
    ans = min(ans, dfs(i + 1, x, y + t[i]));
  if (sum - x - y + t[i] <= 860)
    ans = min(ans, dfs(i + 1, x, y));
  memo[i][x][y] = ans;
  return ans;
}

int main(void) {
  set_memo();
  cin >> N;
  t.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> t[i];
    sum += t[i];
  }
  cout << dfs(0, 0, 0) << endl;
  return 0;
}