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

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
// typedef tuple<ll,ll,ll,ll> tp;
// typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-7;
const int inf = 1e9;
const ll INF = 2e18;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  string out[] = {{".,!? "}, {"abc"},  {"def"}, {"ghi"}, {"jkl"},
                  {"mno"},   {"pqrs"}, {"tuv"}, {"wxyz"}};
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int now = -1, co = 0;
    s += "0";
    rep(i, s.size()) {
      if (s[i] == '0') {
        co--;
        if (now + 1)
          cout << out[now][co % out[now].size()];
        now = -1;
        co = 0;
      } else {
        now = s[i] - '1';
        co++;
      }
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
// typedef tuple<ll,ll,ll,ll> tp;
// typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-7;
const int inf = 1e9;
const ll INF = 2e18;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  int n;
  while (cin >> n, n) {
    int co = 0;
    rep(i, n) loop(j, i + 1, n + 1) if ((i + j) * (j - i + 1) / 2 == n) co++;
    cout << co << endl;
  }
}
Problem p01131 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

using namespace std;

int main() {
  char *dic[] = {"",    ".,!? ", "abc",  "def", "ghi",
                 "jkl", "mno",   "pqrs", "tuv", "wxyz"};
  int len[] = {-1, 5, 3, 3, 3, 3, 3, 4, 3, 4};
  int n;
  scanf("%d", &n);
  while (n--) {
    char s[1025];
    scanf("%s", s);
    char bef = '@';
    int cnt = 0;
    for (int i = 0; s[i]; i++) {
      if (s[i] == '0') {
        if (cnt > 0)
          putchar(dic[bef - '0'][(cnt - 1) % len[bef - '0']]);
        cnt = 0;
        bef = '@';
      } else {
        cnt++;
        bef = s[i];
      }
    }
    putchar('\\n');
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

using namespace std;

int main() {
  char *dic[] = {"",    ".,!? ", "abc",  "def", "ghi",
                 "jkl", "mno",   "pqrs", "tuv", "wxyz"};
  int len[] = {-1, 5, 3, 3, 3, 3, 3, 4, 3, 4};
  int n;
  scanf("%d", &n);
  while (n--) {
    char s[80];
    scanf("%s", s);
    char bef = '@';
    int cnt = 0;
    for (int i = 0; s[i]; i++) {
      if (s[i] == '0') {
        if (cnt > 0)
          putchar(dic[bef - '0'][(cnt - 1) % len[bef - '0']]);
        cnt = 0;
        bef = '@';
      } else {
        cnt++;
        bef = s[i];
      }
    }
    putchar('\\n');
  }
  return 0;
}
Problem p01131 (C++) — buggy submission, verdict: Runtime Error

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

vector<vector<char>> sett = {
    {'.', ',', '!', '?', ' '}, {'a', 'b', 'c'}, {'d', 'e', 'f'},
    {'g', 'h', 'i'},           {'j', 'k', 'l'}, {'m', 'n', 'o'},
    {'p', 'q', 'r', 's'},      {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'}};

int main() {
  int N;
  cin >> N;
  vector<string> anss;
  for (int i = 0; i < N; i++) {
    string inp;
    cin >> inp;
    string ans;
    int count = 0;
    int pre = 0;
    for (int j = 0; j < inp.size(); j++) {
      if (inp[j] == '0') {
        if (count == 0)
          continue;
        ans.push_back(sett[pre - 1][(count - 1) % sett[pre - 1].size()]);
        count = 0;
      } else {
        pre = inp[j] - '0';
        count++;
      }
    }
    anss.push_back(ans);
  }
  for (int i = 0; i < N; i++) {
    cout << anss[i] << endl;
  }
}


Error: -11

Fixed submission:

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

vector<vector<char>> sett = {
    {'.', ',', '!', '?', ' '}, {'a', 'b', 'c'}, {'d', 'e', 'f'},
    {'g', 'h', 'i'},           {'j', 'k', 'l'}, {'m', 'n', 'o'},
    {'p', 'q', 'r', 's'},      {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'}};

int main() {
  int N;
  cin >> N;
  vector<vector<char>> anss;
  for (int i = 0; i < N; i++) {
    string inp;
    cin >> inp;
    vector<char> ans;
    int count = 0;
    char pre = '+';
    for (int j = 0; j < sizeof(inp); j++) {
      if (inp[j] == '0') {
        if (count == 0)
          continue;
        const char A = pre;
        int B = atoi(&A);
        ans.push_back(sett[B - 1][(count - 1) % sett[B - 1].size()]);
        count = 0;
      } else {
        pre = inp[j];
        count++;
      }
    }
    anss.push_back(ans);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < sizeof(anss[i]); j++) {
      cout << anss[i][j];
    }
    cout << endl;
  }
}
Problem p01131 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

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

int main() {
  int num = 0;
  cin >> num;
  string dat[12] = {"",    ".,!? ", "abc",  "def", "ghi",
                    "jkl", "mno",   "pqrs", "tuv", "wxyz"};
  rep(i, num) {
    string str;
    cin >> str;
    vector<int> hit(10, 0);
    rep(j, (int)str.size()) {
      hit[str[j] - '0'] += 1;
      if (j == 0 || str[j - 1] == '0') {
      } else if (str[j] == '0') {
        int tmp = str[j - 1] - '0', n = hit[tmp];
        while (1) {
          if (n <= (int)dat[tmp].size()) {
            break;
          }
          n -= (int)dat[tmp].size();
        }
        printf("%c", dat[tmp][n - 1]);
        rep(i, 10) { hit[i] = 0; }
      }
    }
    printf("\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

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

int main() {
  int num = 0;
  cin >> num;
  string dat[12] = {"",    ".,!? ", "abc",  "def", "ghi",
                    "jkl", "mno",   "pqrs", "tuv", "wxyz"};
  rep(i, num) {
    string str;
    cin >> str;
    vector<int> hit(10, 0);
    rep(j, (int)str.size()) {
      hit[str[j] - '0'] += 1;
      if (j == 0 || str[j - 1] == '0') {
      } else if (str[j] == '0') {
        int tmp = str[j - 1] - '0', n = hit[tmp];
        while (n <= (int)dat[tmp].size()) {
          n -= (int)dat[tmp].size();
        }
        printf("%c", dat[tmp][n - 1]);
        rep(i, 10) { hit[i] = 0; }
      }
    }
    printf("\\n");
  }
  return 0;
}
Problem p01131 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string key[] = {".,!? ", "abc",  "def", "ghi", "jkl",
                    "mno",   "pqrs", "tuv", "wxyz"};
    string input;
    cin >> input;
    stringstream b(input);
    int num = 0, count = 0;
    while (1) {
      char c;
      if (!(b >> c))
        break;
      int input = c - '0';
      if (input != 0) {
        count++;
        num = input;
      } else {
        if (count != 0)
          cout << key[num - 1][(count - 1) % key[num - 1].size()];
        num = 0;
        count = 0;
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string key[] = {".,!?, ", "abc",  "def", "ghi", "jkl",
                    "mno",    "pqrs", "tuv", "wxyz"};
    string input;
    cin >> input;
    stringstream b(input);
    int num = 0, count = 0;
    while (1) {
      char c;
      if (!b >> c)
        break;
      int input = c - '0';
      if (input != 0) {
        count++;
        num = input;
      } else {
        if (count != 0)
          cout << key[num - 1][(count - 1) % key[num - 1].size()];
        num = 0;
        count = 0;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p01131 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

string list[] = {".,!? ", "abc",  "def", "ghi", "jkl",
                 "mno",   "pqrs", "tuv", "wxyz"};

string s;
bool input() {
  s = "";
  if (!(cin >> s)) {
    return false;
  }
  return true;
}

string solve() {
  string res = "";
  int n = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      if (n == -1 || i == 0)
        continue;
      int tmp = s[i - 1] - '0';
      res += list[tmp - 1][n % list[tmp - 1].size()];
      n = -1;
    } else {
      n++;
    }
  }
  return res;
}

int main() {
  int c;
  cin >> c;
  for (int i = 0; i < c; i++) {
    input();
    string ans = solve();
    if (ans.size() != 0)
      cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

string list[] = {".,!? ", "abc",  "def", "ghi", "jkl",
                 "mno",   "pqrs", "tuv", "wxyz"};

string s;
bool input() {
  s = "";
  if (!(cin >> s)) {
    return false;
  }

  return true;
}

string solve() {
  string res = "";
  int n = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      if (n == -1 || i == 0)
        continue;
      int tmp = s[i - 1] - '0';
      res += list[tmp - 1][n % list[tmp].size()];
      n = -1;
    } else {
      n++;
    }
  }
  return res;
}

int main() {
  int c;
  cin >> c;
  for (int i = 0; i < c; i++) {
    input();
    string ans = solve();
    if (ans.size() != 0)
      cout << ans << endl;
  }
}
Problem p01132 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define repn(i, n) for (int i = n; i >= 0; i--)
typedef long long int ll;

int main() {
  int n, pay;
  int m[4], p[5] = {10, 50, 100, 500, 9999999}, cm[4];
  bool b = true;
  while (1) {

    cin >> n;

    pay = 0;
    if (n == 0)
      break;
    if (b)
      b = false;
    else
      cout << endl;
    rep(i, 4) {
      cm[i] = 0;
      cin >> m[i];
      pay += m[i] * p[i];
    }
    pay -= n;
    // cout<<pay<<endl;
    repn(i, 3) {
      while (pay >= p[i] && pay % p[i + 1]) {
        pay -= p[i];
        m[i]--;
        // cout<<pay<<endl;
      }
    }
    rep(i, 4) {
      if (m[i] > 0)
        cout << p[i] << " " << m[i] << endl;
    }
    // cout<<endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define repn(i, n) for (int i = n; i >= 0; i--)
typedef long long int ll;

int main() {
  int n, pay;
  int m[4], p[5] = {10, 50, 100, 500, BIG}, cm[4];
  while (1) {
    cin >> n;
    pay = 0;
    rep(i, 4) {
      cm[i] = 0;
      cin >> m[i];
      pay += m[i] * p[i];
    }
    pay -= n;
    repn(i, 3) {
      while (pay >= p[i] && m[i] && pay % p[i + 1]) {
        pay -= p[i];
        m[i]--;
      }
    }
    rep(i, 4) {
      if (m[i])
        cout << p[i] << " " << m[i] << endl;
    }
    cout << endl;
  }
  return 0;
}
Problem p01132 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  Int s;
  Int flg = 0;
  while (cin >> s, s) {
    if (flg)
      cout << endl;
    flg = 1;
    Int n = 4;
    Int ans = 1e8;
    vector<Int> v(n), a(n, 0);
    for (Int i = 0; i < 4; i++)
      cin >> v[i];
    vector<Int> c({10, 50, 100, 500});
    for (Int i = 0; i <= v[0]; i++) {
      for (Int j = 0; j <= v[1]; j++) {
        for (Int k = 0; k <= v[2]; k++) {
          for (Int l = 0; l <= v[3]; l++) {
            Int tmp = c[0] * i + c[1] * j + c[2] * k + c[3] * l - s;
            if (tmp < 0)
              continue;
            Int res = v[0] + v[1] + v[2] + v[3];
            res -= i + j + k + l;
            for (Int x = 3; x >= 0; x--) {
              res += tmp / c[x];
              tmp %= c[x];
            }
            // cout<<i<<" "<<j<<" "<<k<<" "<<l<<":"<<res<<endl;
            if (res < ans) {
              ans = res;
              a[0] = i;
              a[1] = j;
              a[2] = k;
              a[3] = l;
            }
          }
        }
      }
    }
    for (Int i = 0; i < 4; i++)
      if (a[i])
        cout << c[i] << " " << a[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  Int n;
  while (cin >> n, n) {
    vector<Int> m(n);
    vector<vector<Int>> v(n);
    for (Int i = 0; i < n; i++) {
      cin >> m[i];
      v[i].resize(m[i]);
      for (Int j = 0; j < m[i]; j++)
        cin >> v[i][j];
    }

    Int k;
    cin >> k;
    set<Int> l;
    for (Int i = 0; i < k; i++) {
      Int x;
      cin >> x;
      l.emplace(x);
    }

    vector<Int> ans;
    for (Int i = 0; i < n; i++) {
      Int cnt = 0;
      for (Int j = 0; j < m[i]; j++)
        cnt += l.count(v[i][j]);

      if (cnt == k)
        ans.emplace_back(i);
    }

    if (ans.size() == 1u)
      cout << ans[0] + 1 << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
Problem p01132 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int n[10000], c10[10000], c50[10000], c100[10000], c500[10000], i = 0;

  while (1) {
    cin >> n[i];
    if (n[i] == 0)
      break;
    cin >> c10[i] >> c50[i] >> c100[i] >> c500[i];
    i++;
  }

  for (int j = 0; j < i; j++) {
    int m, k10, k50, k100, k500;
    m = c10[j] * 10 + c50[j] * 50 + c100[j] * 100 + c500[j] * 500 - n[j];

    k500 = c500[j] - m / 500;
    if (k500 < 0)
      k500 = 0;
    m -= 500 * (m / 500);

    k100 = c100[j] - m / 100;
    if (k100 < 0)
      k100 = 0;
    m -= 100 * (m / 100);

    k50 = c50[j] - m / 50;
    if (k50 < 0)
      k50 = 0;
    m -= 50 * (m / 50);

    k10 = c10[j] - m / 10;
    if (k10 < 0)
      k10 = 0;
    m -= 10 * (m / 10);

    if (k10 > 0)
      cout << 10 << " " << k10 << endl;
    if (k50 > 0)
      cout << 50 << " " << k50 << endl;
    if (k100 > 0)
      cout << 100 << " " << k100 << endl;
    if (k500 > 0)
      cout << 500 << " " << k500 << endl;
    if (j < i - 1)
      cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n[1000], c10[1000], c50[1000], c100[1000], c500[1000], i = 0;

  while (1) {
    cin >> n[i];
    if (n[i] == 0)
      break;
    cin >> c10[i] >> c50[i] >> c100[i] >> c500[i];
    i++;
  }

  for (int j = 0; j < i; j++) {
    int m, k10, k50, k100, k500;
    m = c10[j] * 10 + c50[j] * 50 + c100[j] * 100 + c500[j] * 500 - n[j];

    k500 = c500[j] - m / 500;
    if (k500 < 0)
      k500 = 0;
    m -= 500 * (m / 500);

    k100 = c100[j] - m / 100;
    if (k100 < 0)
      k100 = 0;
    m -= 100 * (m / 100);

    k50 = c50[j] - m / 50;
    if (k50 < 0)
      k50 = 0;
    m -= 50 * (m / 50);

    k10 = c10[j] - m / 10;
    if (k10 < 0)
      k10 = 0;
    m -= 10 * (m / 10);

    if (k10 > 0)
      cout << 10 << " " << k10 << endl;
    if (k50 > 0)
      cout << 50 << " " << k50 << endl;
    if (k100 > 0)
      cout << 100 << " " << k100 << endl;
    if (k500 > 0)
      cout << 500 << " " << k500 << endl;
    if (j < i - 1)
      cout << endl;
  }

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

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {

  int n;
  int y[4] = {10, 50, 100, 500};
  int f = 0;
  while (cin >> n, n != 0) {
    if (f != 0)
      cout << endl;
    int s = 0;
    int x[4] = {0};
    for (int i = 0; i < 4; i++) {
      cin >> x[i];
      s += x[i] * y[i];
    }
    s -= n;
    int k = 3;
    int z[4] = {0};
    while (s > 0) {
      if (s - y[k] >= 0) {
        z[k]++;
        s -= y[k];
      } else
        k--;
    }
    for (int i = 0; i < 4; i++) {
      if (x[i] > z[i])
        cout << y[i] << " " << x[i] - z[i] << endl;
    }
    f = 1;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {

  int n;
  int f = 0;
  int e[4] = {10, 50, 100, 500};
  string x[4] = {"10", "50", "100", "500"};
  while (cin >> n, n != 0) {
    if (f != 0)
      cout << endl;
    map<string, int> s;
    s["10"] = 0;
    s["50"] = 0;
    s["100"] = 0;
    s["500"] = 0;
    int y[4] = {0};

    for (int i = 0; i < 4; i++) {
      cin >> y[i];
    }
    int k = 0;
    while (n > 0) {

      if (y[k] > 0 && n - y[k] >= 0) {
        s[x[k]]++;
        n -= e[k];
        y[k]--;
      } else
        k++;
    }

    for (int i = 0; i < s.size(); i++) {
      if (s[x[i]] > 0)
        cout << x[i] << " " << s[x[i]] << endl;
    }
    f = 1;
  }
}
Problem p01132 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF 10000

int temp[5] = {10, 50, 100, 500}, n;

int foo(int temp2[]) {
  int a = 0, temp3[4] = {}, f = 0, b = 0;
  for (int i = 0; i < 4; i++)
    a += temp2[i] * temp[i]; // cout<<"a "<<a<<endl;
  a = a - n;
  for (int i = 3; i >= 0; i--) {
    b += temp3[i] += a / temp[i]; // cout<<a<<endl;
    a -= (a / temp[i]) * temp[i]; // cout<<a<<endl;
    f += temp3[i] * temp2[i];
  }
  // for(int i =0; i < 4; i++){cout<<temp2[i]<<" "<<temp3[i]<<endl;}
  return f ? INF * 2 : b;
}

int main() {
  int a, b, c, d, e, f, count = 0;
  while (1) {
    int ans[4] = {}, mi = INF, temp2[4];
    cin >> n;

    if (!n)
      break;
    if (count++)
      cout << endl;
    cin >> a >> b >> c >> d;

    for (int i = 0; i <= a; i++)
      for (int j = 0; j <= b; j++)
        for (int k = 0; k <= c; k++)
          for (int l = 0; l <= d; l++) {
            int temp2[] = {i, j, k, l};
            e = i * 10 + j * 50 + k * 100 + l * 500;
            f = i + j + k + l; // cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;
            if (e >=
                n) { // cout<<foo(temp2)<<" "<<e<<" "<<n<<" "<<f<<" "<<mi<<endl;
              if (foo(temp2) - f < mi) {
                ans[0] = i;
                ans[1] = j;
                ans[2] = k;
                ans[3] = l;
                mi = foo(temp2) - f;
              }
            }
          }

    for (int i = 0; i < 4; i++)
      if (ans[i])
        cout << temp[i] << " " << ans[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int g, a, b, c, r, t;
  while (1) {
    int d = 0, q = 0, w = 0, e = 0;
    cin >> g;
    if (g == 0)
      break;
    cin >> a >> b >> c >> d;

    t = g;

    q = t / 500;
    if (d >= q)
      t -= q * 500;
    else {
      t -= d * 500;
      q = d;
    }
    w = t / 100;
    if (c >= w)
      t -= w * 100;
    else {
      t -= 100 * c;
      w = c;
    }
    e = t / 50;
    if (b >= e)
      t -= e * 50;
    else {
      t -= 50 * b;
      e = b;
    }

    r = t / 10;
    if (a >= r)
      t -= r * 50;
    else {
      t -= 50 * a;
      r = a;
    }

    while (t) {
      if (b - e >= 1 && t <= 50) {
        e++;
        if (t > 50)
          t -= 50;
        else
          t = 0;
      } else
        break;
    }

    while (t) {
      if (c - w >= 1 && t <= 100) {
        w++;
        if (t > 100)
          t -= 100;
        else
          t = 0;
      } else
        break;
    }

    while (t) {
      if (d - q >= 1) {
        q++;
        if (t > 500)
          t -= 500;
        else
          t = 0;
      }
    }

    if (r)
      cout << "10 " << r << endl;
    if (e)
      cout << "50 " << e << endl;
    if (w)
      cout << "100 " << w << endl;
    if (q)
      cout << "500 " << q << endl;
  }
  return 0;
}
Problem p01132 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[4], b[4], c[4] = {10, 50, 100, 500}, d, e = 0, ju, i;
  while (cin >> d, d) {
    if (e)
      cout << endl;
    e++;
    int sum = 0;
    for (i = 0; i < 4; i++) {
      cin >> a[i];
      sum += a[i] * c[i];
    }
    sum -= d;
    for (i = 4; i--;) {
      b[i] = sum / c[i];
      sum %= c[i];
    }
    for (i = 0; i < 4; i++) {
      ju = a[i] - b[i];
      if (ju > 0)
        cout << c[i] << ' ' << ju << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0, i;
  while (cin >> n, n != 0) {
    if (c)
      cout << endl;
    c++;
    int a[4], b[4] = {0, 0, 0, 0}, syu[4] = {10, 50, 100, 500}, sca = n;
    for (i = 0; i < 4; i++)
      cin >> a[i];
    if (a[0] > 0) {
      for (i = 0; sca % 50 != 0; i++) {
        b[0]++;
        sca -= 10;
        a[0]--;
      }
      if (a[0] != 0 && a[0] % 5 == 0)
        for (i = 0; a[0] > 0; i++) {
          b[0] += 5;
          sca -= 50;
          a[0] -= 5;
        }
    }
    if (sca % 100 != 0 && sca % 50 != 0) {
      sca -= 10;
      a[1]--;
      b[1]++;
    }
    if (a[1] > 0) {
      for (i = 0; sca % 100 != 0; i++) {
        b[1]++;
        sca -= 50;
        a[1]--;
      }
      if (a[1] != 0 && a[1] % 2 == 0)
        for (i = 0; a[1] > 0; i++) {
          b[1] += 2;
          sca -= 100;
          a[0] -= 2;
        }
    }
    if (sca % 500 != 0 && sca % 100 != 0) {
      sca -= 50;
      a[2]--;
      b[2]++;
    }
    if (a[2] > 0) {
      for (i = 0; sca % 500 != 0; i++) {
        b[2]++;
        sca -= 100;
        a[2]--;
      }
      if (a[2] != 0 && a[2] % 5 == 0)
        for (i = 0; a[2] > 0; i++) {
          b[2] += 5;
          sca -= 500;
          a[0] -= 5;
        }
    }
    if (sca % 500 != 0)
      b[3]++;
    else
      b[3] = sca / 500;
    for (i = 0; i < 4; i++)
      if (0 < b[i])
        cout << syu[i] << " " << b[i] << endl;
  }
}