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

#include <bits/stdc++.h>

using namespace std;

int P, N[6];
const int coin[6] = {1, 5, 10, 50, 100, 500};

int calc(int x) {
  int res = 0;
  for (int i = 5; i >= 0; i--) {
    if (x >= coin[i]) {
      res += x / coin[i];
      x %= coin[i];
    }
  }
  return res;
}

int c(int x) {
  int res = 0;
  for (int i = 5; i >= 0; i--) {
    int use = x / coin[i];
    if (use > N[i]) {
      res += N[i];
      x -= N[i] * coin[i];
    } else {
      res += use;
      x %= coin[i];
    }
  }
  return res;
}

int main() {
  while (cin >> P) {
    int end = P;
    for (int i = 0; i < 6; i++) {
      cin >> N[i];
      end += N[i];
    }
    if (end == 0) {
      break;
    }
    int res = (1 << 29);
    for (int i = P; i <= 2 * P; i++) {
      int x = c(i);
      res = min(res, x + calc(i - P));
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int P, N[6];
const int coin[6] = {1, 5, 10, 50, 100, 500};

int calc(int x) {
  int res = 0;
  for (int i = 5; i >= 0; i--) {
    if (x >= coin[i]) {
      res += x / coin[i];
      x %= coin[i];
    }
  }
  return res;
}

bool c(int x) {
  int dp[x + 1];
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j <= x; j++) {
      if (dp[j] >= 0) {
        dp[j] = N[i];
      } else if (j < coin[i] || dp[j - coin[i]] <= 0) {
        dp[j] = -1;
      } else {
        dp[j] = dp[j - coin[i]] - 1;
      }
    }
  }
  return (dp[x] >= 0);
}

int main() {
  int end, sum;
  while (cin >> P) {
    end = P;
    for (int i = 0; i < 6; i++) {
      cin >> N[i];
      end += N[i];
      sum += coin[i] * N[i];
    }
    if (end == 0) {
      break;
    }
    int res = (1 << 29);
    for (int i = P; i <= 2 * P; i++) {
      if (!c(i)) {
        continue;
      }
      res = min(res, calc(i) + calc(i - P));
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00614 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int value[6] = {1, 5, 10, 50, 100, 500};
int ns[6];
int p;

#define INF (1 << 28)

int count_coins(int n) {
  int cnt = 0;
  for (int i = 5; i >= 0; i--) {
    int c = n / value[i];
    n -= c * value[i];
    cnt += c;
    if (n == 0)
      break;
  }
  return cnt;
}

int solve(int index, int rem) {
  if (rem == 0)
    return 0;
  if (rem < 0)
    return count_coins(-rem);
  if (index < 0)
    return INF;
  int min_pay = INF;

  int s = rem / value[index];
  if (s < ns[index]) {
    min_pay = min(solve(index - 1, rem - value[index] * s) + s,
                  solve(index - 1, rem - value[index] * (s + 1)) + s + 1);
    return min_pay;
  }
  return solve(index - 1, rem - value[index] * ns[index]) + ns[index];
}

int main() {
  while (cin >> p) {
    if (p == 0)
      break;
    for (int i = 0; i < 6; i++)
      cin >> ns[i];

    int min_total = INF;
    for (int i = 0; i <= 500; i++) {
      min_total = min(min_total, solve(5, p + i) + count_coins(i));
    }
    cout << min_total << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int value[6] = {1, 5, 10, 50, 100, 500};
int ns[6];
int p;

#define INF (1 << 28)

int count_coins(int n) {
  int cnt = 0;
  for (int i = 5; i >= 0; i--) {
    int c = n / value[i];
    n -= c * value[i];
    cnt += c;
    if (n == 0)
      break;
  }
  return cnt;
}

int solve(int index, int rem) {
  if (rem == 0)
    return 0;
  if (rem < 0)
    return count_coins(-rem);
  if (index < 0)
    return INF;
  int min_pay = INF;

  int s = rem / value[index];
  if (s < ns[index]) {
    min_pay = min(solve(index - 1, rem - value[index] * s) + s,
                  solve(index - 1, rem - value[index] * (s + 1)) + s + 1);
    return min_pay;
  }
  if (s == ns[index]) {
    return solve(index - 1, rem - value[index] * s) + s;
  }
  for (int i = 0; i <= ns[index]; i++) {
    min_pay = min(min_pay, solve(index - 1, rem - value[index] * i) + i);
  }
  return min_pay;
}

int main() {
  while (cin >> p) {
    if (p == 0)
      break;
    for (int i = 0; i < 6; i++)
      cin >> ns[i];
    cout << solve(5, p) << endl;
  }
  return 0;
}
Problem p00614 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <numeric>
#include <vector>

using namespace std;

#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)

typedef vector<int> vi;

const int INFTY = 1 << 29;

const int vals[] = {1, 5, 10, 50, 100, 500};

int getpay(int ns[], int x) {
  int res = 0;
  per(i, 6) {
    int use = min(x / vals[i], ns[i]);
    res += use;
    x -= use * vals[i];
  }
  return x > 0 ? -1 : res;
}

int getchange(int x) {
  static int memo[666001];
  if (!x || memo[x])
    return memo[x];
  int &res = memo[x];
  per(i, 6) {
    res += x / vals[i];
    x %= vals[i];
  }
  return res;
}

int main() {
  for (int p, ns[6]; scanf("%d", &p), p;) {
    rep(i, 6) scanf("%d", ns + i);
    int pmax = inner_product(ns, ns + 6, vals, 0);

    int res = INFTY;
    repi(i, p, pmax + 1) {
      int pay = getpay(ns, i);
      if (pay != -1)
        res = min(res, pay + getchange(i - p));
    }
    printf("%d\\n", res);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <vector>

using namespace std;

#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)

typedef vector<int> vi;

const int PMAX = 666000;
const int INFTY = 1 << 29;

const int vals[] = {1, 5, 10, 50, 100, 500};

int getchange(int x) {
  static int memo[PMAX + 1];
  if (!x || memo[x])
    return memo[x];
  int &res = memo[x];
  rep(i, 6) {
    res += x / vals[i];
    x %= vals[i];
  }
  return res;
}

int main() {
  for (int p, ns[6]; scanf("%d", &p), p;) {
    rep(i, 6) scanf("%d", ns + i);

    vi dp(PMAX + 1, INFTY);
    dp[0] = 0;
    rep(i, 6) {
      vi use(PMAX + 1);
      rep(j, PMAX + 1 - vals[i]) {
        if (dp[j] == -1 || use[j] >= ns[i])
          continue;
        dp[j + vals[i]] = min(dp[j + vals[i]], dp[j] + 1);
        use[j + vals[i]] = use[j] + 1;
      }
    }

    int res = INFTY;
    repi(i, p, PMAX + 1) {
      if (dp[i] == -1)
        continue;
      res = min(res, dp[i] + getchange(i - p));
    }
    printf("%d\\n", res);
  }

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

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

#define NCOIN 6
const int coins[NCOIN] = {1, 5, 10, 50, 100, 500};
const int infty = 1 << 28;

int PaymentAndChange(int N, int v[], bool &possible) {
  int ret = 0;
  for (int i = NCOIN - 1; i >= 0; --i) {
    int t = N / coins[i];
    if (t > v[i]) {
      N -= coins[i] * v[i];
      ret += v[i];
    } else {
      N -= coins[i] * t;
      ret += t;
    }
  }
  if (N == 0)
    possible = true;
  else
    possible = false;
  return ret;
}

int main() {
  while (true) {
    int ans = infty;
    int P, maxP = 0;
    int vc[NCOIN] = {
        0,
    };
    scanf("%d", &P);
    if (P == 0)
      break;
    for (int i = 0; i < NCOIN; ++i) {
      scanf("%d", &vc[i]);
      maxP += vc[i] * coins[i];
    }
    for (int iP = P; iP <= maxP; ++iP) {
      bool pos;
      int t = PaymentAndChange(iP, vc, pos);
      if (!pos)
        continue;
      if (t >= ans)
        continue;
      t += PaymentAndChange(iP - P, vc, pos);
      if (!pos)
        continue;
      ans = min(ans, t);
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define NCOIN 6
const int coins[NCOIN] = {1, 5, 10, 50, 100, 500};
const int infty = 1 << 28;
int PaymentAndChange(int N, int v[], bool &possible) {
  int ret = 0;
  for (int i = NCOIN - 1; i >= 0; --i) {
    int t = N / coins[i];
    if (t > v[i]) {
      N -= coins[i] * v[i];
      ret += v[i];
    } else {
      N -= coins[i] * t;
      ret += t;
    }
  }
  if (N == 0)
    possible = true;
  else
    possible = false;
  return ret;
}

int main() {
  while (true) {
    int ans = infty;
    int P, maxP = 0;
    int vc[NCOIN] = {
        0,
    };
    cin >> P;
    if (P == 0)
      break;
    for (int i = 0; i < NCOIN; ++i) {
      cin >> vc[i];
      maxP += vc[i] * coins[i];
    }
    for (int iP = P; iP <= maxP; ++iP) {
      bool pos;
      int t = PaymentAndChange(iP, vc, pos);
      if (!pos)
        continue;
      t += PaymentAndChange(iP - P, vc, pos);
      if (!pos)
        continue;
      ans = min(ans, t);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00614 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
int value[6] = {1, 5, 10, 50, 100, 500};

int returnCoinNum(int receive) {
  int ret = 0;
  for (int i = 5; i >= 0; --i) {
    ret += receive / value[i];
    receive -= receive / value[i] * value[i];
  }
  return (ret);
}

void solve() {
  int p;
  vector<int> coin(6);
  while (cin >> p) {
    for (int i = 0; i < 6; ++i) {
      cin >> coin[i];
    }
    if (p == 0) {
      break;
    }
    int minv = 1e9;
    for (int i = p; i <= p + 500; ++i) {
      int use = 0;
      int remain = i;
      for (int j = 5; j >= 0; --j) {
        int payable = min(remain / value[j], coin[j]);
        remain -= payable * value[j];
        use += payable;
      }
      if (remain != 0) {
        continue;
      }
      minv = min(use + returnCoinNum(i - p), minv);
    }
    cout << minv << endl;
  }
}

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

Error: -11

Fixed submission:

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

using namespace std;
int value[6] = {1, 5, 10, 50, 100, 500};
int p;
int minv = 1e9;
int memo[6][300000];

int returnCoinNum(int receive) {
  int ret = 0;
  for (int i = 5; i >= 0; --i) {
    ret += receive / value[i];
    receive -= receive / value[i] * value[i];
  }
  return (ret);
}

int dfs(int sum, int pos, int use, vector<int> &coin) {
  if (memo[pos][sum]) {
    return (memo[pos][sum]);
  }
  if (pos < 0) {
    return (0);
  }
  int res = 0;
  if (sum >= p) {
    minv = min(minv, use + returnCoinNum(sum - p));
    return (minv);
  }
  if (coin[pos] > 0) {
    coin[pos]--;
    int temp = dfs(sum + value[pos], pos, use + 1, coin);
    coin[pos]++;
    res = min(temp, dfs(sum, pos - 1, use, coin));
  } else {
    res = dfs(sum, pos - 1, use, coin);
  }
  return (memo[pos][sum] = res);
}

void solve() {
  vector<int> coin(6);
  while (cin >> p) {
    for (int i = 0; i < 6; ++i) {
      cin >> coin[i];
    }
    if (p == 0) {
      break;
    }
    dfs(0, 5, 0, coin);
    cout << minv << endl;
  }
}

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int i, j;
  int a[6] = {1, 5, 10, 50, 100, 500}, b[6], c[670000];
  fill(c, c + 670000, -1);
  int n;
  while (cin >> n) {
    int m = 0;
    for (i = 0; i < 6; ++i) {
      cin >> b[i];
      m += a[i] * b[i];
    }
    if (n == 0)
      break;
    int mn = 1 << 30;
    for (i = n; i <= m; ++i) {
      int ct = 0, sm = 0;
      for (j = 5; j >= 0; --j) {
        if (a[j] * b[j] > i - sm) {
          ct += (i - sm) / a[j];
          sm += (i - sm) / a[j] * a[j];
        } else {
          ct += b[j];
          sm += a[j] * b[j];
        }
      }
      if (i > sm)
        continue;
      if (c[i - n] < 0) {
        int p = i - n;
        int ct = 0;
        for (j = 5; j >= 0; --j) {
          ct += p / a[j];
          p -= p / a[j] * a[j];
        }
        c[i - n] = ct;
      }
      ct += c[i - n];
      mn = min(mn, ct);
    }
    cout << mn << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int a[6], n[6], p;
unsigned fn(int q, int r, int s) {
  int i;
  unsigned mn = -1;
  if (q == 6) {
    if (s >= p) {
      s -= p;
      mn = r;
      for (i = 0; i < 6; i++) {
        mn += s / a[i];
        s -= s / a[i] * a[i];
      }
    }
  } else {
    for (i = 0; i < min(n[q], (p - s) / a[q] + 2) + 1; i++)
      mn = min(mn, fn(q + 1, r + i, s + a[q] * i));
  }
  return mn;
}
int main() {
  a[0] = 500;
  a[1] = 100;
  a[2] = 50;
  a[3] = 10;
  a[4] = 5;
  a[5] = 1;
  while (cin >> p >> n[5] >> n[4] >> n[3] >> n[2] >> n[1] >> n[0] &&
         p + n[0] + n[1] + n[2] + n[3] + n[4] + n[5])
    cout << fn(0, 0, 0) << endl;
  return 0;
}
Problem p00614 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF (1e9)
#define M 666001
using namespace std;
int P, d[6], c[6] = {1, 5, 10, 50, 100, 500};
int f, ans, sum, z[M];

int cal(int x) {
  int res = 0;
  for (int i = 5; i >= 0; i--)
    res += x / c[i], x = x % c[i];
  return res;
}

int cal2(int x) {
  int res = 0;
  for (int i = 5; i >= 0; i--) {
    int p = min(x / c[i], d[i]);
    res += p;
    if (p)
      x -= p * c[i];
  }
  if (!x)
    return res;
  return -1;
}

int main() {
  for (int i = 0; i < M; i++)
    z[i] = cal(i);
  while (1) {
    cin >> P;
    f = sum = 0;
    for (int i = 0; i < 6; i++) {
      cin >> d[i], sum += d[i] * c[i];
      if (d[i])
        f = 1;
    }
    if (!f)
      break;
    ans = INF;
    for (int i = P; i <= sum; i++) {
      int r = cal2(i);
      if (r != -1)
        ans = min(ans, r + z[i - P]);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define N 100
#define M 26
using namespace std;
string s;
int p, len;

string bnf(bool rev) {
  string res;
  int cnt = 0;
  while (p != len) {
    if (s[p] == '+')
      p++, cnt++;
    if (s[p] == '-')
      p++, cnt--;
    if ('A' <= s[p] && s[p] <= 'Z')
      res += ((s[p++] + cnt + M * N) - 'A') % M + 'A', cnt = 0;
    if (s[p] == '?')
      res += s[p++], cnt = 0;
    if (s[p] == '[')
      p++, res += bnf(true);
    if (s[p] == ']') {
      p++;
      break;
    }
  }
  if (rev)
    reverse(res.begin(), res.end());
  return res;
}

int main() {
  while (1) {
    cin >> s;
    if (s == ".")
      break;
    len = s.size();
    p = 0;
    string ans = bnf(false);
    for (int i = 0; i < (int)ans.size(); i++)
      if (ans[i] == '?')
        ans[i] = 'A';
    cout << ans << endl;
  }
  return 0;
}
Problem p00615 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}

void bsort(int a[], int lim) {
  int tmp;

  for (int i = 0; i <= lim - 1; i++)
    for (int j = lim; i < j; j--) {
      if (a[j - 1] > a[j]) {
        tmp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = tmp;
      }
    }
}

int main() {
  int n, m, i;
  int out;
  int t[20002];

  while (std::cin >> n >> m, (n || m)) {
    std::memset(t, 0, sizeof(t));
    out = 0;

    for (i = 1; i <= n + m; i++) {
      std::cin >> t[i];
    }

    bsort(t, n + m);

    for (i = 0; i <= m + n; i++) {
      t[i] = t[i + 1] - t[i];
    }
    for (i = 0; i <= m + n - 1; i++) {
      out = max(out, t[i]);
    }

    std::cout << out << std::endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}

void bsort(int a[], int lim) {
  int tmp;

  for (int i = 0; i <= lim - 1; i++)
    for (int j = lim; i < j; j--) {
      if (a[j - 1] > a[j]) {
        tmp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = tmp;
      }
    }
}

int main() {
  int n, m, i;
  int out;
  int t[1000];

  while (std::cin >> n >> m, (n || m)) {
    std::memset(t, 0, sizeof(t));
    out = 0;

    for (i = 1; i <= n + m; i++) {
      std::cin >> t[i];
    }

    bsort(t, n + m);

    for (i = 0; i <= m + n; i++) {
      t[i] = t[i + 1] - t[i];
    }
    for (i = 0; i <= m + n - 1; i++) {
      out = max(out, t[i]);
    }

    std::cout << out << std::endl;
  }

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

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

using namespace std;

int main(void) {
  int n, m, max, i, x;
  vector<int> time;

  while (cin >> n >> m) {
    time.push_back(0);
    if (n == 0 && m == 0)
      break;
    for (i = 0; i < n + m; i++) {
      cin >> x;
      time.push_back(x);
    }
    sort(time.begin(), time.end());
    max = -1;
    for (i = 0; i < n + m; i++) {
      max = (max < time[i + 1] - time[i]) ? time[i + 1] - time[i] : max;
    }
    cout << max << endl;
    time.clear();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {
  int n, m, max, i, x;

  while (1) {
    cin >> n >> m;
    for (i = 0; i < n + m; i++) {
      cin >> x;
      max = (i == 0) ? x : (max < x - max) ? x - max : max;
    }
    cout << max << endl;
  }

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

#include <cstdio>
#include <iostream>
#define N 1000000
int tl[N];

using namespace std;

void sort(int, int);
int syori(int, int);

int main() {
  int n, m, i, ans;
  while (1) {
    for (i = 0; i < N; i++) {
      tl[i] = 0;
    }

    cin >> n;
    cin >> m;

    if (m == 0 && n == 0)
      break;

    for (i = 1; i <= n; i++) {
      cin >> tl[i];
    }

    for (i = n + 1; i <= (m + n); i++) {
      cin >> tl[i];
    }

    sort(m, n);

    ans = syori(n, m);

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

void sort(int m, int n) {
  int i, j, max, hi;

  for (i = 0; i <= (m + n); i++) {
    max = i;
    for (j = i; j <= (m + n); j++) {
      if (tl[j] < tl[max])
        max = j;
    }
    hi = tl[max];
    tl[max] = tl[i];
    tl[i] = hi;
  }

  //  for(i=0;i<=(m+n);i++){
  // cout << tl[i] << endl;;

  //}
}

int syori(int n, int m) {
  int i, max = 0;
  for (i = 0; i < (m + n); i++) {
    if (tl[i + 1] - tl[i] >= max)
      max = tl[i + 1] - tl[i];
  }

  return max;
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>
#define N 10000000
int tl[N];

using namespace std;

void sort(int, int);
int syori(int, int);

int main() {
  int n, m, i, ans;
  while (1) {
    for (i = 0; i < N; i++) {
      tl[i] = 0;
    }

    cin >> n;
    cin >> m;

    if (m == 0 && n == 0)
      break;

    for (i = 1; i <= n; i++) {
      cin >> tl[i];
    }

    for (i = n + 1; i <= (m + n); i++) {
      cin >> tl[i];
    }

    sort(m, n);

    ans = syori(n, m);

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

void sort(int m, int n) {
  int i, j, max, hi;

  for (i = 0; i <= (m + n); i++) {
    max = i;
    for (j = i; j <= (m + n); j++) {
      if (tl[j] < tl[max])
        max = j;
    }
    hi = tl[max];
    tl[max] = tl[i];
    tl[i] = hi;
  }

  //  for(i=0;i<=(m+n);i++){
  // cout << tl[i] << endl;;

  //}
}

int syori(int n, int m) {
  int i, max = 0;
  for (i = 0; i < (m + n); i++) {
    if (tl[i + 1] - tl[i] >= max)
      max = tl[i + 1] - tl[i];
  }

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

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

// #define int long long
#define DEBUG 0
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  if (DEBUG) {                                                                 \\
    cerr << #o << " " << o << endl;                                            \\
  }
#define dumpc(o)                                                               \\
  if (DEBUG) {                                                                 \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
  int a[20010] = {};
  for (int n, m; cin >> n >> m && (n || m);) {
    rep(i, 0, n + m) cin >> a[i];
    a[n + m] = 0;
    sort(a, a + n + m + 1);
    int M = 0;
    rep(i, 1, n + m + 1) { M = max(M, a[i] - a[i - 1]); }
    cout << M << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

// #define int long long
#define DEBUG 0
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  if (DEBUG) {                                                                 \\
    cerr << #o << " " << o << endl;                                            \\
  }
#define dumpc(o)                                                               \\
  if (DEBUG) {                                                                 \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
  int a[10010] = {};
  for (int n, m; cin >> n >> m && (n || m);) {
    rep(i, 0, n + m) cin >> a[i];
    a[n + m] = 0;
    sort(a, a + n + m + 1);
    int M = 0;
    rep(i, 1, n + m + 1) { M = max(M, a[i] - a[i - 1]); }
    cout << M << endl;
  }
  return 0;
}
Problem p00615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m, a[20001];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n + m; i++)
      scanf("%d", &a[i]);
    sort(a, a + n + m + 1);
    int ret = 0;
    for (int i = 1; i <= n + m; i++) {
      ret = max(ret, a[i] - a[i - 1]);
    }
    printf("%d\\n", ret);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int n, m, a[20000];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n + m; i++)
      scanf("%d", &a[i]);
    sort(a, a + n + m + 1);
    int ret = 0;
    for (int i = 1; i <= n + m; i++) {
      ret = max(ret, a[i] - a[i - 1]);
    }
    printf("%d\\n", ret);
  }
  return 0;
}
Problem p00615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
#define FOR(i, b, n) for (int i = (b); i < (n); ++i)
#define rep(i, n) FOR(i, 0, n)
int main() {
  int a, b, data[20000];
  while (cin >> a >> b, a || b) {
    rep(i, a + b) cin >> data[i];
    sort(data, data + a + b);
    int ans = data[0];
    FOR(i, 1, a + b) ans = max(ans, data[i] - data[i - 1]);
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
#define FOR(i, b, n) for (int i = (b); i < (n); ++i)
#define rep(i, n) FOR(i, 0, n)
int main() {
  int a, b, data[10000];
  while (cin >> a >> b, a || b) {
    rep(i, a + b) cin >> data[i];
    sort(data, data + a + b);
    int ans = data[0];
    FOR(i, 1, a + b) ans = max(ans, data[i] - data[i - 1]);
    cout << ans << endl;
  }
}