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

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

#define int long long

signed main() {
  int n, d;
  while (cin >> n >> d, n) {
    vector<int> m(n), sum(n, 0);
    vector<vector<int>> c(n);
    for (int i = 0; i < n; i++) {
      cin >> m[i];
      c[i] = vector<int>(m[i]);
      for (int j = 0; j < m[i]; j++) {
        cin >> c[i][j];
        sum[i] += c[i][j];
      }
      m[i]--;
    }

    bool flag = true;
    bool flag2 = true;
    while (flag && flag2) {
      flag = false;
      for (int i = 0; i < n; i++) {
        int ma = 0;
        if (m[i] == -1)
          continue;
        for (int j = 0; j < n; j++) {
          if (i == j)
            continue;
          ma = max(ma, sum[j]);
        }
        if (abs(ma - (sum[i] - c[i][m[i]])) > d)
          continue;
        sum[i] -= c[i][m[i]];
        m[i]--;
        if (m[i] == -1)
          flag2 = false;
        flag = true;
        break;
      }
    }
    if (!flag2)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

#define int long long

signed main() {
  int n, d;
  while (cin >> n >> d, n) {
    vector<int> m(n), sum(n, 0);
    vector<vector<int>> c(n);
    for (int i = 0; i < n; i++) {
      cin >> m[i];
      c[i] = vector<int>(m[i]);
      for (int j = 0; j < m[i]; j++) {
        cin >> c[i][j];
        sum[i] += c[i][j];
      }
      m[i]--;
    }

    bool flag = true;
    bool flag2 = true;
    while (flag && flag2) {
      flag = false;
      for (int i = 0; i < n; i++) {
        int ma = 0;
        for (int j = 0; j < n; j++) {
          if (i == j)
            continue;
          ma = max(ma, sum[j]);
        }
        if (abs(ma - (sum[i] - c[i][m[i]])) > d)
          continue;
        sum[i] -= c[i][m[i]];
        m[i]--;
        if (m[i] == -1)
          flag2 = false;
        flag = true;
      }
    }
    if (!flag2)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

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

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

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

using namespace std;

int main() {
  int n, d;
  while (cin >> n >> d, n) {
    vector<vector<int>> v(n);
    rep(i, n) {
      int m;
      cin >> m;
      v[i].resize(m + 1);
      rep(j, m) cin >> v[i][j + 1];
      rep(j, m) v[i][j + 1] += v[i][j];
    }
    if (n == 1) {
      cout << "Yes" << endl;
      continue;
    }

    vector<int> idx(n);
    while (1) {
      // rep(i, n){
      //	cout << v[i][idx[i]] << ' ';
      // }cout << endl;
      bool upd = false;
      vector<int> x(n);
      rep(i, n) x[i] = v[i][idx[i]];
      sort(x.begin(), x.end());
      int m1 = x[0], m2 = x[1];

      rep(i, n) {
        if (idx[i] + 1 == v[i].size())
          continue;
        int nm = v[i][idx[i]] == m1 ? m2 : m1;
        if (v[i][idx[i] + 1] <= nm + d) {
          ++idx[i];
          upd = true;
          break;
        }
      }
      if (!upd)
        break;
    }
    bool ok = true;
    rep(i, n) {
      if (idx[i] + 1 != v[i].size())
        ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

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

using namespace std;

int main() {
  int n, d;
  while (cin >> n >> d, n) {
    vector<vector<int>> v(n);
    rep(i, n) {
      int m;
      cin >> m;
      v[i].resize(m);
      rep(j, m) cin >> v[i][j];
      rep(j, m - 1) v[i][j + 1] += v[i][j];
    }
    if (n == 1) {
      cout << "Yes" << endl;
      continue;
    }

    vector<int> idx(n);
    while (1) {
      bool upd = false;
      vector<int> x(n);
      rep(i, n) x[i] = v[i][idx[i]];
      sort(x.begin(), x.end());
      int m1 = x[0], m2 = x[1];

      rep(i, n) {
        if (idx[i] + 1 == v[i].size())
          continue;
        int nm = v[i][idx[i]] == m1 ? m2 : m1;
        if (v[i][idx[i] + 1] <= nm + d) {
          ++idx[i];
          upd = true;
          break;
        }
      }
      if (!upd)
        break;
    }
    bool ok = true;
    rep(i, n) {
      if (idx[i] + 1 != v[i].size())
        ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
  }

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

#include <bits/stdc++.h>
#define int long long
#define N 101
using namespace std;
const int INF = 1LL << 55;
int n, d;
vector<int> A[N];
int Sum[N];

int getMax() { return *max_element(Sum, Sum + n); }
int getMin() { return *min_element(Sum, Sum + n); }

int getIdx() {
  int sa = INF;
  int res = -1;
  for (int i = 0; i < n; i++) {
    if (A[i].empty())
      continue;
    int sum = Sum[i] + A[i].back();
    Sum[i] += A[i].back();
    int mn = getMin();
    Sum[i] -= A[i].back();
    if (sum - mn > d)
      continue;
    if (sum - mn < sa)
      sa = sum - mn, res = i;
  }
  return res;
}

bool clear() {
  for (int i = 0; i < n; i++)
    if (A[i].size())
      return 0;
  return 1;
}

bool solve() {
  memset(Sum, 0, sizeof(Sum));
  while (!clear()) {
    int idx = getIdx();
    if (idx == -1)
      return 0;
    Sum[idx] += A[idx].back();
    A[idx].pop_back();
  }
  return 1;
}

signed main() {
  while (1) {
    cin >> n >> d;
    if (!n && !d)
      break;

    for (int i = 0; i < n; i++) {
      int k;
      cin >> k;
      A[i].resize(k);
      for (int j = 0; j < k; j++)
        cin >> A[i][j];
      reverse(A[i].begin(), A[i].end());
    }
    cout << (solve() ? "Yes" : "No") << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int n, d, Sum[101];
vector<int> A[101];

int get() {
  int mx = -1, mx2 = -1, res = -1;
  for (int i = 0; i < n; i++) {
    int sum = Sum[i] - A[i].back();
    if (mx < sum)
      mx = sum, mx2 = Sum[i], res = i;
    else if (mx == sum && mx2 < Sum[i])
      mx2 = Sum[i], res = i;
  }
  return res;
}

bool check() {
  int nx;
  while ((nx = get()) != -1) {
    Sum[nx] -= A[nx].back(), A[nx].pop_back();
    int mx = -1, mn = 1e9;
    for (int i = 0; i < n; i++)
      mx = max(mx, Sum[i]), mn = min(mn, Sum[i]);
    if (mx - mn > d)
      return 0;
  }
  return 1;
}

int main() {
  while (1) {
    cin >> n >> d;
    if (!n && !d)
      break;
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      A[i].resize(m), Sum[i] = 0;
      for (int j = 0; j < m; j++)
        cin >> A[i][j], Sum[i] += A[i][j];
      A[i].push_back(0);
    }

    cout << (check() ? "Yes" : "No") << endl;
  }
  return 0;
}
Problem p01294 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  for (int n, d; cin >> n >> d, n;) {
    vector<int> c[100];
    int s[100] = {};
    int nm = 0;
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      c[i].resize(m);
      for (int j = 0; j < m; j++) {
        cin >> c[i][j];
        nm++;
        s[i] += c[i][j];
      }
    }
    if (n == 1) {
      nm = 0;
    }
    for (; nm; nm--) {
      vector<int> v(begin(s), begin(s) + n);
      sort(v.rbegin(), v.rend());
      for (int i = 0; i < n; i++) {
        if (!c[i].empty() &&
            ((s[i] == v[0]) ? v[1] : v[0]) - (s[i] - c[i].back()) <= d) {
          s[i] -= c[i].back();
          c[i].pop_back();
          goto next;
        }
      }
      break;
    next:;
    }
    cout << (nm ? "No" : "Yes") << endl;
  }
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  for (int n, d; cin >> n >> d, n;) {
    vector<int> c[100];
    int s[100] = {};
    int nm = 0;
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      c[i].resize(m);
      for (int j = 0; j < m; j++) {
        cin >> c[i][j];
        nm++;
        s[i] += c[i][j];
      }
    }
    if (n == 1) {
      nm = 0;
    }
    for (; nm; nm--) {
      vector<int> v(begin(s), begin(s) + n);
      sort(v.rbegin(), v.rend());
      for (int i = 0; i < n; i++) {
        if (!v.empty() &&
            ((s[i] == v[0]) ? v[1] : v[0]) - (s[i] - c[i].back()) <= d) {
          s[i] -= c[i].back();
          c[i].pop_back();
          goto next;
        }
      }
      break;
    next:;
    }
    cout << (nm ? "No" : "Yes") << endl;
  }
}
Problem p01294 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using lint = long long;
using ldouble = long double;

bool solve() {
  int N, D;
  cin >> N >> D;
  if (N == 0)
    return false;

  vector<vector<int>> C(N);
  for (auto &v : C) {
    int m;
    cin >> m;
    v.resize(m);
    for (auto &c : v)
      cin >> c;
    reverse(v.begin(), v.end());
  }

  if (N == 1) {
    cout << "Yes" << endl;
    return true;
  }

  vector<int> sum(N);
  for (int i = 0; i < N; ++i) {
    sum[i] = accumulate(C[i].begin(), C[i].end(), 0);
  }

  vector<int> itr(N, 0);
  while (true) {
    int minsum = *min_element(sum.begin(), sum.end());

    for (int i = 0; i < N; ++i) {
      while (itr[i] < C[i].size() && sum[i] - C[i][itr[i]] >= minsum) {
        sum[i] -= C[i][itr[i]++];
      }
    }

    if (*max_element(sum.begin(), sum.end()) == 0)
      break;

    auto sums = sum;
    sort(sums.rbegin(), sums.rend());

    int nxt = -1, minminsum = 1 << 30;
    for (int i = 0; i < N; ++i) {
      int ma = (sum[i] == sums[0] ? sums[1] : sums[0]);
      if (itr[i] == C[i].size() || ma - (sum[i] - C[i][itr[i]]) > D)
        continue;
      if (sum[i] - C[i][itr[i]] < minminsum) {
        nxt = i;
        minminsum = sum[i] - C[i][itr[i]];
      }
    }

    if (nxt < 0) {
      cout << "No" << endl;
      return true;
    }

    sum[nxt] -= C[nxt][itr[nxt]++];
  }

  cout << "Yes" << endl;
  return true;
}

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


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using lint = long long;
using ldouble = long double;

bool solve() {
  int N, D;
  cin >> N >> D;
  if (N == 0)
    return false;

  vector<vector<int>> C(N);
  for (auto &v : C) {
    int m;
    cin >> m;
    v.resize(m);
    for (auto &c : v)
      cin >> c;
  }

  vector<int> sum(N);
  for (int i = 0; i < N; ++i) {
    sum[i] = accumulate(C[i].begin(), C[i].end(), 0);
  }
  int minsum = *min_element(sum.begin(), sum.end());

  priority_queue<tuple<int, int, int>> que;
  // 総和, 次のミサイル * -1, 番号
  for (int i = 0; i < N; ++i) {
    que.emplace(sum[i], -C[i][0], i);
  }

  vector<int> itr(N, 0);
  while (!que.empty()) {
    int id = get<2>(que.top());
    que.pop();

    if (sum[id] - minsum > D) {
      cout << "No" << endl;
      return true;
    }

    sum[id] -= C[id][itr[id]];
    minsum = min(minsum, sum[id]);

    if (++itr[id] < C[id].size()) {
      que.emplace(sum[id], -C[id][itr[id]], id);
    }
  }

  cout << "Yes" << endl;
  return true;
}

int main() {
  while (solve()) {
  }
  return 0;
}
Problem p01294 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (1 << 28)
#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)

using namespace std;

int n, d;

int main() {
  while (cin >> n >> d, n | d) {
    deque<int> deq[n];
    int sum[n];
    rep(i, n) sum[i] = 0;
    int total = 0;
    rep(i, n) {
      int k, c;
      cin >> k;
      total += k;
      rep(j, k) {
        cin >> c;
        sum[i] += c;
        deq[i].push_back(c);
      }
      reverse(deq[i].begin(), deq[i].end());
    }

    bool ok = true;

    rep(i, total) {
      rep(j, n) {
        if (deq[j].empty())
          continue;
        int mex, men;
        mex = -inf;
        men = inf;
        rep(k, n) {
          int cost = sum[k] - (k == j ? deq[j].front() : 0);
          mex = max(mex, cost);
          men = min(men, cost);
        }

        if (mex - men <= d) {
          sum[j] -= deq[j].front();
          deq[j].pop_front();
          break;
        }
        if (j == n - 1)
          ok = false;
      }
      if (!ok)
        break;
    }

    cout << (ok ? "Yes" : "No") << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (1 << 28)
#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)

using namespace std;

int n, d;

int main() {
  while (cin >> n >> d, n | d) {
    deque<int> deq[n];
    int sum[n];
    rep(i, n) sum[i] = 0;
    int total = 0;
    rep(i, n) {
      int k, c;
      cin >> k;
      total += k;
      rep(j, k) {
        cin >> c;
        sum[i] += c;
        deq[i].push_back(c);
      }
    }

    bool ok = true;

    rep(i, total) {

      rep(j, n) {
        int mex, men;
        mex = -inf;
        men = inf;
        rep(k, n) {
          int cost = sum[k] - (k == j ? deq[j].front() : 0);
          mex = max(mex, cost);
          men = min(men, cost);
        }

        if (mex - men <= d) {
          sum[j] -= deq[j].front();
          deq[j].pop_front();
          continue;
        }
        if (j == n - 1)
          ok = false;
      }
      if (!ok)
        break;
    }

    cout << (ok ? "Yes" : "No") << endl;
  }
  return 0;
}
Problem p01294 (C++) — buggy submission, verdict: Runtime Error

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

bool solve(int n, int d) {
  vector<vector<int>> c(n);

  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int buf;
      cin >> buf;
      c[i].push_back(buf);
    }
  }
  if (n == 1)
    return true;

  while (true) {
    vector<int> sum(n);
    for (int i = 0; i < n; i++)
      sum[i] = accumulate(c[i].begin(), c[i].end(), 0);
    int midx = max_element(sum.begin(), sum.end()) - sum.begin();
    int smidx = midx ? 0 : 1;
    for (int i = 0; i < n; i++) {
      if (i != midx && sum[smidx] < sum[i])
        smidx = i;
    }
    bool isok = false;
    for (int i = 0; i < n && !isok; i++) {
      if (i == midx)
        continue;
      if (c[i].size() > 0 && sum[midx] - (sum[i] - c[i].back()) <= d) {
        c[i].pop_back();
        isok = true;
      }
    }
    if (isok)
      continue;
    if (c[midx].size() == 0 || sum[smidx] - (sum[midx] - c[midx].back()) > d) {
      break;
    }
    c[midx].pop_back();
  }
  return all_of(c.begin(), c.end(),
                [](const vector<int> &vec) { return vec.empty(); });
}
int main() {
  int n, d;
  while (cin >> n >> d, n) {
    cout << (solve(n, d) ? "Yes" : "No") << endl;
  }
  return 0;
}


Error: 0
0
0
0
2
2
1


Fixed submission:

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

bool solve(int n, int d) {
  vector<vector<int>> c(n);

  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int buf;
      cin >> buf;
      c[i].push_back(buf);
    }
  }
  if (n == 1)
    return true;

  while (true) {
    vector<int> sum(n);
    for (int i = 0; i < n; i++)
      sum[i] = accumulate(c[i].begin(), c[i].end(), 0);
    int midx = max_element(sum.begin(), sum.end()) - sum.begin();
    int smidx = midx ? 0 : 1;
    for (int i = 0; i < n; i++) {
      if (i != midx && sum[smidx] < sum[i])
        smidx = i;
    }
    bool isok = false;
    for (int i = 0; i < n && !isok; i++) {
      if (i == midx)
        continue;
      if (c[i].size() > 0 && sum[midx] - (sum[i] - c[i].back()) <= d) {
        c[i].pop_back();
        isok = true;
      }
    }
    if (isok)
      continue;
    if (c[midx].size() == 0 || sum[smidx] - (sum[midx] - c[midx].back()) > d) {
      break;
    }
    c[midx].pop_back();
  }
  for (int i = 0; i < n; i++) {
    cerr << c[i].size() << endl;
  }
  return all_of(c.begin(), c.end(),
                [](const vector<int> &vec) { return vec.empty(); });
}
int main() {
  int n, d;
  while (cin >> n >> d, n) {
    cout << (solve(n, d) ? "Yes" : "No") << endl;
  }
  return 0;
}
Problem p01294 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
int N, D;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int _t, _s;
  while (cin >> N >> D && N) {
    vector<int> m[100];
    vector<int> sum(N, 0);
    rep(i, N) {
      cin >> _t;
      rep(j, _t) {
        cin >> _s;
        m[i].push_back(_s);
        sum[i] += _s;
      }
    }
    while (true) {
      bool updated = false;
      rep(i, N) while (m[i].size()) {
        sum[i] -= m[i].back();
        if (*max_element(sum.begin(), sum.end()) - sum[i] <= D) {
          m[i].pop_back();
          updated = true;
        } else {
          sum[i] += m[i].back();
          break;
        }
      }
      if (!updated)
        break;
    }
    rep(i, N - 1) sum[i + 1] += sum[i];
    if (sum[N - 1] == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
vector<int> m[100];
map<vector<int>, bool> memo;
int N, D;
bool dfs(vector<int> it) {
  if (memo.count(it))
    return memo[it];
  int mi = INF, ma = -1;
  rep(i, N) {
    mi = min(mi, m[i][it[i]]);
    ma = max(ma, m[i][it[i]]);
  }
  if (ma - mi > D)
    return memo[it] = false;
  bool updated = false;
  rep(i, N) {
    if (it[i] == m[i].size() - 1)
      continue;
    vector<int> temp = it;
    updated = true;
    temp[i]++;
    if (dfs(temp))
      return memo[it] = true;
  }
  return memo[it] = updated ? false : true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int _t, _s;
  while (cin >> N >> D && N) {
    int max_t = 0;
    rep(i, N) {
      cin >> _t;
      m[i] = vector<int>(_t, 0);
      max_t = max(max_t, _t);
      rep(j, _t) {
        cin >> m[i][j];
        if (j)
          m[i][j] += m[i][j - 1];
      }
    }
    vector<int> temp(N, 0);
    if (dfs(temp))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
Problem p01294 (C++) — buggy submission, verdict: Runtime Error

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

const int INF = 1 << 28;

int main() {
  for (int n, d; cin >> n >> d && (n | d);) {
    vector<vector<int>> c(n);
    for (int i = 0; i < n; ++i) {
      int m;
      cin >> m;
      c[i].resize(m);
      for (int j = 0; j < m; ++j)
        cin >> c[i][j];
    }
    vector<int> sum(n);
    for (int i = 0; i < n; ++i) {
      sum[i] = accumulate(c[i].begin(), c[i].end(), 0);
    }
    while (1) {
      bool update = false;
      for (int i = 0; i < n; ++i) {
        if (c[i].empty())
          continue;
        sum[i] -= c[i].back();
        if (*max_element(sum.begin(), sum.end()) -
                *min_element(sum.begin(), sum.end()) <=
            d) {
          c[i].pop_back();
          update = true;
        } else {
          sum[i] += c[i].back();
        }
      }
      if (!update)
        break;
    }
    if (accumulate(sum.begin(), sum.end(), 0)) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

const int INF = 1 << 28;

int main() {
  for (int n, d; cin >> n >> d && (n | d);) {
    vector<vector<int>> c(n);
    for (int i = 0; i < n; ++i) {
      int m;
      cin >> m;
      c[i].resize(m);
      for (int j = 0; j < m; ++j)
        cin >> c[i][j];
    }
    vector<int> sum(n);
    for (int i = 0; i < n; ++i) {
      sum[i] = accumulate(c[i].begin(), c[i].end(), 0);
    }
    while (1) {
      bool update = false;
      for (int i = 0; i < n; ++i) {
        sum[i] -= c[i].back();
        if (*max_element(sum.begin(), sum.end()) -
                *min_element(sum.begin(), sum.end()) <=
            d) {
          c[i].pop_back();
          update = true;
        } else {
          sum[i] += c[i].back();
        }
      }
      if (!update)
        break;
    }
    if (accumulate(sum.begin(), sum.end(), 0)) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

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

using namespace std;

typedef long long ll;

ll f(int a) {
  ll ofset = 0;
  for (ll c = 9, d = 1;; c *= 10, d++) {
    if (a <= c)
      return ofset + (a - 1) * d + 1;
    a -= c;
    ofset += c * d;
  }
}

int main() {
  for (int n, k; scanf("%d%d", &n, &k), n;) {
    int lo = 1, hi = 1e9;
    while (lo < hi) {
      int mi = (lo + hi + 1) / 2;
      if (f(mi) <= n)
        lo = mi;
      else
        hi = mi - 1;
    }

    int a = lo;
    for (int c = f(a) - n; c < k; a++) {
      char s[16];
      sprintf(s, "%d", a);
      for (int i = 0; s[i]; i++) {
        if (0 <= c && c < k)
          putchar(s[i]);
        c++;
      }
    }
    putchar('\\n');
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>

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

using namespace std;

typedef long long ll;

int main() {
  ll order[9];
  rep(i, 9) order[i] = (i + 1) * 9 * (ll)pow(10., i);

  for (int n, k; scanf("%d%d", &n, &k), n;) {
    int p;
    for (p = 0; p < 9; p++) {
      if (n <= order[p])
        break;
      n -= order[p];
    }

    int startnum = (int)pow(10., p) + (n - 1) / (p + 1);
    int startdgt = (n - 1) % (p + 1);
    char ans[128] = "", tmp[16];
    sprintf(tmp, "%d", startnum);
    strcat(ans, tmp + startdgt);
    for (int i = 0, j = startnum + 1; i < k; i += p + 1, j++) {
      sprintf(tmp, "%d", j);
      strcat(ans, tmp);
    }
    ans[k] = '\\0';
    puts(ans);
  }

  return 0;
}