prithivMLmods/Coder-Stat huggingface dataset:
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define lli long long int
#define REP(i, n) for (int i = 0; i < n; i++)
#define DEBUG 1

lli target, n;
lli flag = 0;

void calc(lli now, lli left, lli sum, lli *data) {
  lli plus[3] = {10000, 5000, 1000};
  if (sum > target)
    return;
  if (flag == 1)
    return;
  if (now == 3) {
    if (sum == target && left == 0) {
      cout << data[0] << " " << data[1] << " " << data[2] << endl;
      flag = 1;
    }
    return;
  }
  for (lli i = left; i >= 0; i--) {
    data[now] = i;
    calc(now + 1, left - i, sum + i * plus[now], data);
    data[now] = 0;
  }
}

int main() {

  cin >> n >> target;

  lli data[3] = {-1, -1, -1};

  calc(0, n, 0, data);

  if (flag == 0) {
    cout << "-1 -1 -1" << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define lli long long int
#define REP(i, n) for (int i = 0; i < n; i++)
#define DEBUG 1

lli target, n;
lli flag = 0;

void calc(lli now, lli left, lli sum, lli *data) {
  lli plus[3] = {10000, 5000, 1000};
  if (sum > target)
    return;
  if (flag == 1)
    return;
  if (now == 3) {
    if (sum == target && left == 0) {
      cout << data[0] << " " << data[1] << " " << data[2] << endl;
      flag = 1;
    }
    return;
  }
  if (now == 2) {
    data[now] = left;
    calc(now + 1, 0, sum + left * plus[now], data);
  } else {
    for (lli i = left; i >= 0; i--) {
      data[now] = i;
      calc(now + 1, left - i, sum + i * plus[now], data);
      data[now] = 0;
    }
  }
}

int main() {

  cin >> n >> target;

  lli data[3] = {-1, -1, -1};

  calc(0, n, 0, data);

  if (flag == 0) {
    cout << "-1 -1 -1" << endl;
  }
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
  char ac, uc[100000];
  string manji;
  cin >> a >> b;
  for (int i = 0;; i++) {
    for (int j = 0;; j++) {

      if (i * 10000 + j * 5000 + (a - i - j) * 1000 == b && a >= i + j) {
        cout << i << ' ' << j << ' ' << a - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
  char ac, uc[100000];
  string manji;
  cin >> a >> b;
  for (int i = 0; a >= i; i++) {
    for (int j = 0; a >= i + j; j++) {
      if (i * 10000 + j * 5000 + (a - i - j) * 1000 == b) {
        cout << i << ' ' << j << ' ' << a - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  int n, y;
  scanf("%d %d", &n, &y);
  int s = 0;
  int flag = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        s = i * 10000 + j * 5000 + k * 1000;
        if (s == y && i + j + k == n) {
          flag = 1;
          printf("%d %d %d\n", i, j, k);
          return 0;
        }
      }
    }
  }
  if (flag == 0)
    printf("-1 -1 -1\n");
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int n, y;
  scanf("%d %d", &n, &y);
  int s = 0;
  int flag = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      s = i * 10000 + j * 5000;
      if (i + j <= n && s + (n - i - j) * 1000 == y) {
        flag = 1;
        printf("%d %d %d\n", i, j, n - i - j);
        return 0;
      }
    }
  }
  if (flag == 0)
    printf("-1 -1 -1\n");
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  int a, b, c;
  std::cin >> a >> b;
  c = b;
  while (true) {
    int flag = 0;
    for (int i = 0; i <= b / 10000; i++) {
      c = b;
      c -= 10000 * i;
      if (i == a && c == 0) {
        std::cout << i << ' ' << 0 << ' ' << 0 << std::endl;
        flag += 1;
        break;
      }
      for (int j = 0; j <= b / 5000; j++) {
        int c = b;
        c -= 10000 * i + 5000 * j;
        if (i + j == a && c == 0) {
          std::cout << i << ' ' << j << ' ' << 0 << std::endl;
          flag += 1;
          break;
        }
        for (int k = 0; k <= b / 1000; k++) {
          int c = b;
          c -= 10000 * i + 5000 * j + 1000 * k;
          if (i + j + k == a && c == 0) {
            std::cout << i << ' ' << j << ' ' << k << std::endl;
            flag += 1;
            break;
          }
        }
        if (flag == 1) {
          break;
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 0)
      std::cout << -1 << ' ' << -1 << ' ' << -1 << std::endl;
    break;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  int a, b, c;
  std::cin >> a >> b;
  c = b;
  while (true) {
    int flag = 0;
    for (int i = 0; i <= b / 10000; i++) {
      c = b;
      c -= 10000 * i;
      if (i == a && c == 0) {
        std::cout << i << ' ' << 0 << ' ' << 0 << std::endl;
        flag += 1;
        break;
      }
      if (c > 5000 * (a - i)) {
        continue;
      }
      for (int j = 0; j <= b / 5000; j++) {
        int c = b;
        c -= 10000 * i + 5000 * j;
        if (i + j == a && c == 0) {
          std::cout << i << ' ' << j << ' ' << 0 << std::endl;
          flag += 1;
          break;
        }
        for (int k = 0; k <= b / 1000; k++) {
          int c = b;
          c -= 10000 * i + 5000 * j + 1000 * k;
          if (i + j + k == a && c == 0) {
            std::cout << i << ' ' << j << ' ' << k << std::endl;
            flag += 1;
            break;
          }
        }
        if (flag == 1) {
          break;
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 0)
      std::cout << -1 << ' ' << -1 << ' ' << -1 << std::endl;
    break;
  }
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int N, Y;
int main() {
  cin >> N >> Y;
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= N; j++)
      for (int k = 0; k <= N; k++)
        if (i * 10000 + j * 5000 + k * 1000 == Y && i + j + k == N) {
          cout << i << " " << j << " " << k;
          return 0;
        }

  cout << "-1"
       << " "
       << "-1"
       << " "
       << "-1";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int N, Y;
int main() {
  cin >> N >> Y;
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= N; j++) {
      int k = N - i - j;

      if (k >= 0 && i * 10000 + j * 5000 + k * 1000 == Y) {
        cout << i << " " << j << " " << k;
        return 0;
      }
    }

  cout << "-1"
       << " "
       << "-1"
       << " "
       << "-1";
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, Y, flag = 0;
  int x = 10000, y = 5000, z = 1000;
  cin >> N >> Y;

  // cout << N << Y << endl;

  for (int i = N; i >= 0; i--) {
    for (int j = N; j >= 0; j--) {
      for (int k = N; k >= 0; k--) {
        if ((i + j + k) != N) {
          // cout << "break" << endl;
          continue;
        } else if ((i + j + k) == N && (x * i + y * j + z * k) == Y) {
          cout << i << " " << j << " " << k << endl;
          flag = 1;
        }

        if (flag == 1) {
          break;
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 1) {
      break;
    }
  }
  if (flag == 0) {
    cout << "-1 -1 -1" << endl;
  }
}


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

int main() {
  int N, Y, flag = 0;
  int x = 10000, y = 5000, z = 1000;
  cin >> N >> Y;

  // cout << N << Y << endl;

  for (int i = N; i >= 0; i--) {
    for (int j = N - i; j >= 0; j--) {
      for (int k = N - i - j; k >= 0; k--) {
        if ((i + j + k) != N) {
          // cout << "break" << endl;
          continue;
        } else if ((i + j + k) == N && (x * i + y * j + z * k) == Y) {
          cout << i << " " << j << " " << k << endl;
          flag = 1;
        }

        if (flag == 1) {
          break;
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 1) {
      break;
    }
  }
  if (flag == 0) {
    cout << "-1 -1 -1" << endl;
  }
}
Problem p03471 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, s, e) for (int i = s; i < (e); i++)
#define All(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, Y;
  cin >> N >> Y;
  Y /= 1000;

  vector<vector<int>> ans(Y + 1, vector<int>(3, 0));
  // can, 5000, 10000
  ans[Y][0] = 1;
  for (int i = Y; i >= 0; i--) {
    if (ans[i][0]) {
      if (i - 4 >= 0 && !ans[i - 4][0]) {
        ans[i - 4][0] = 1;
        ans[i - 4][1] += ans[i][1] + 1;
        ans[i - 4][2] = ans[i][2];
      }
      if (i - 9 >= 0 && !ans[i - 9][0]) {
        ans[i - 9][0] = 1;
        ans[i - 9][1] = ans[i][1];
        ans[i - 9][2] += ans[i][2] + 1;
      }
    }
  }
  if (!ans[N][0] || N - ans[N][1] - ans[N][2] < 0)
    cout << "-1 -1 -1"
         << "\n";
  else
    cout << ans[N][2] << " " << ans[N][1] << " " << N - ans[N][1] - ans[N][2]
         << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, s, e) for (int i = s; i < (e); i++)
#define All(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, Y;
  cin >> N >> Y;
  Y /= 1000;

  vector<vector<int>> ans(Y + 1, vector<int>(3, 0));
  // can, 5000, 10000
  ans[Y][0] = 1;
  for (int i = Y; i >= 0; i--) {
    if (ans[i][0]) {
      if (i - 4 >= 0 && !ans[i - 4][0]) {
        ans[i - 4][0] = 1;
        ans[i - 4][1] += ans[i][1] + 1;
        ans[i - 4][2] = ans[i][2];
      }
      if (i - 9 >= 0 && !ans[i - 9][0]) {
        ans[i - 9][0] = 1;
        ans[i - 9][1] = ans[i][1];
        ans[i - 9][2] += ans[i][2] + 1;
      }
    }
  }
  if (N > Y || !ans[N][0] || N - ans[N][1] - ans[N][2] < 0)
    cout << "-1 -1 -1"
         << "\n";
  else
    cout << ans[N][2] << " " << ans[N][1] << " " << N - ans[N][1] - ans[N][2]
         << "\n";
  return 0;
}
Problem p03471 (Python)

Buggy submission (status: Time Limit Exceeded):
N, Y = map(int, input().split())
for y in range(9):
    for x in range(N + 1):
        for z in range(N + 1):
            if Y == (10000 * x) + (5000 * y) + (1000 * z) and x + y + z == N:
                print(x, y, z)
                break
        else:
            continue
        break
    else:
        if y == 8:
            print(-1, -1, -1)
        continue
    break


Fixed submission:
N, Y = map(int, input().split())
for y in range(9):
    for x in range(N + 1):
        if Y == (10000 * x) + (5000 * y) + (1000 * (N - x - y)) and N >= x + y:
            print(x, y, N - x - y)
            break
        else:
            continue
        break
    else:
        if y == 8:
            print(-1, -1, -1)
        continue
    break
Problem p03471 (Python)

Buggy submission (status: Time Limit Exceeded):
n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        for k in range(n + 1 - i - j):
            if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n and not flg:
                flg = True
                print(i, j, k)
                break
        else:
            continue
        break
    else:
        continue
    break

if not flg:
    print(-1, -1, -1)


Fixed submission:
n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = (y - 10000 * i - 5000 * j) // 1000
        if i + j + k == n and not flg:
            flg = True
            print(i, j, k)
            break
    else:
        continue
    break

if not flg:
    print(-1, -1, -1)
Problem p03471 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3


def main():
    args = input().split()
    N = int(args[0])
    Y = int(args[1])

    for num10000 in range(0, N + 1):
        for num5000 in range(0, N + 1 - num10000):
            for num1000 in range(0, N + 1 - num10000 - num5000):
                if num10000 + num5000 + num1000 != N:
                    continue
                value = 10000 * num10000 + 5000 * num5000 + 1000 * num1000
                if value == Y:
                    print(num10000, num5000, num1000)
                    return

    print(-1, -1, -1)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3


def main():
    args = input().split()
    N = int(args[0])
    Y = int(args[1])

    for num10000 in range(0, N + 1):
        for num5000 in range(0, N + 1 - num10000):
            num1000 = N - num10000 - num5000
            value = 10000 * num10000 + 5000 * num5000 + 1000 * num1000
            if value == Y:
                print(num10000, num5000, num1000)
                return

    print(-1, -1, -1)


if __name__ == "__main__":
    main()
Problem p03471 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10**8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Y = map(int, readline().split())
assert Y % 1000 == 0
Y //= 1000


def solve2():
    for x1 in range(N + 1):
        for x2 in range(N - x1 + 1):
            x3 = N - x1 - x2
            if 10 * x1 + 5 * x2 + 1 * x3 == Y:
                print(x1, x2, x3)
                return
    print(-1, -1, -1)


def solve():
    path = [[None] * (Y + 1) for _ in range(N + 1)]
    path[0][0] = -1
    for i in range(1, N + 1):
        for y in range(Y + 1):
            if path[i - 1][y] is None:
                continue
            for b in [1, 5, 10]:
                if y + b > Y:
                    continue
                path[i][y + b] = b

    if path[N][Y] is None:
        print(-1, -1, -1)
        return
    res = collections.Counter()
    m = Y
    for i in range(N, 0, -1):
        b = path[i][m]
        # print(f"path[{i}][{m}] ={b}", file=sys.stderr)
        if b is None:
            raise ValueError(f"path[{i}][{m}] is None")
        res[b] += 1
        m -= b
    print(res[10], res[5], res[1])


if __name__ == "__main__":
    solve2()


Fixed submission:
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10**8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Y = map(int, readline().split())
assert Y % 1000 == 0
Y //= 1000


def solve2():
    for x1 in range(N + 1):
        for x2 in range(N - x1 + 1):
            x3 = N - x1 - x2
            if 10 * x1 + 5 * x2 + 1 * x3 == Y:
                print(x1, x2, x3)
                return
    print(-1, -1, -1)


if __name__ == "__main__":
    solve2()
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int huda[3], kingaku[3] = {10000, 5000, 1000};

bool money(int left_n, int left_y, int y) {
  if (left_y < 0)
    return false;
  bool flag = false;
  if (y == 3) {
    if (left_y == 0 && left_n == 0) {
      return true;
    } else {
      return false;
    }
  }
  for (int n = left_n; n >= 0; n--) {
    if (flag)
      break;
    huda[y] = left_n - n;
    if (money(n, left_y - huda[y] * kingaku[y], y + 1)) {
      flag = true;
      return true;
    }
  }
  if (flag)
    return true;
  else
    return false;
}

int main() {
  long long int n, y;
  cin >> n >> y;
  if (n * 10000 < y) {
    cout << "-1 -1 -1" << endl;
    return 0;
  }
  if (money(n, y, 0)) {
    cout << huda[0] << " " << huda[1] << " " << huda[2] << endl;
  } else
    cout << "-1 -1 -1" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int huda[3], kingaku[3] = {10000, 5000, 1000};

bool money(int left_n, int left_y, int y) {
  if (left_y < 0)
    return false;
  if (left_n * kingaku[y] < left_y)
    return false;
  bool flag = false;
  if (y == 3) {
    if (left_y == 0 && left_n == 0) {
      return true;
    } else {
      return false;
    }
  }
  for (int n = left_n; n >= 0; n--) {
    if (flag)
      break;
    huda[y] = left_n - n;
    if (money(n, left_y - huda[y] * kingaku[y], y + 1)) {
      flag = true;
      return true;
    }
  }
  if (flag)
    return true;
  else
    return false;
}

int main() {
  long long int n, y;
  cin >> n >> y;
  if (n * 10000 < y) {
    cout << "-1 -1 -1" << endl;
    return 0;
  }
  if (money(n, y, 0)) {
    cout << huda[0] << " " << huda[1] << " " << huda[2] << endl;
  } else
    cout << "-1 -1 -1" << endl;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= N; k++) {

        if (i + j + k == N && 10000 * i + 5000 * j + 1000 * k == Y) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
}


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

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

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      for (int k = 0; k <= N - i - j; k++) {

        if (i + j + k == N && 10000 * i + 5000 * j + 1000 * k == Y) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

int main() {
  int N, Y;
  cin >> N >> Y;
  int yukiti = -1, higuti = -1, noguti = -1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= N; k++) {
        int sum = i * 10000 + j * 5000 + k * 1000;
        if (sum == Y && i + j + k == N) {
          yukiti = i;
          higuti = j;
          noguti = k;
        }
      }
    }
  }
  cout << yukiti << " " << higuti << " " << noguti << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

int main() {
  int N, Y;
  cin >> N >> Y;
  int yukiti = -1, higuti = -1, noguti = -1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      int k = N - i - j;
      int sum = i * 10000 + j * 5000 + k * 1000;
      if (sum == Y && i + j + k == N) {
        yukiti = i;
        higuti = j;
        noguti = k;
      }
    }
  }
  cout << yukiti << " " << higuti << " " << noguti << endl;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
  ll n, y, ans = 0;
  cin >> n >> y;
  y /= 1000;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if (i * 10 + 5 * j + k > y)
          break;
        if (10 * i + 5 * j + k == y && i + j + k == n) {
          cout << i << ' ' << j << ' ' << k;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
  ll n, y, ans = 0;
  cin >> n >> y;
  y /= 1000;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; i + j <= n; j++) {
      for (int k = 0; i + j + k <= n; k++) {
        if (10 * i + 5 * j + k == y && i + j + k == n) {
          cout << i << ' ' << j << ' ' << k;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v)                                                            \
  copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v)                                                           \
  copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v)                                                            \
  copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end());                       // 昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>());    // 降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); // 昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v) accumulate((v).begin(), (v).end(), 0LL);

int main() {
  int n, y;
  cin >> n >> y;
  for (int a = 0; a <= n; a++) {
    for (int b = 0; b <= n; b++) {
      if (a + b > n) {
        continue;
      }
      for (int c = 0; c <= n; c++) {
        if (a + b + c != n) {
          continue;
        }
        if (a * 10000 + b * 5000 + c * 1000 == y) {
          cout << a << " " << b << " " << c << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v)                                                            \
  copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v)                                                           \
  copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v)                                                            \
  copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end());                       // 昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>());    // 降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); // 昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v) accumulate((v).begin(), (v).end(), 0LL);

int main() {
  int n, y;
  cin >> n >> y;
  for (int a = 0; a <= n; a++) {
    for (int b = 0; b <= n; b++) {
      if (a + b > n) {
        continue;
      }
      if (a * 10000 + b * 5000 + (n - (a + b)) * 1000 == y) {
        cout << a << " " << b << " " << n - (a + b) << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

void solve(int n, int y) {
  int max = y / 10000;
  for (int i = y; i >= 0; i--) {
    for (int j = 0; j <= 2000; j++) {
      if (i + j > n || i * 10000 + j * 5000 > y)
        break;
      for (int k = 0; k <= 2000; k++) {
        int sum = i * 10000 + j * 5000 + k * 1000;
        int num = i + j + k;
        if (sum == y && num == n) {
          cout << i << " " << j << " " << k << endl;
          return;
        }
      }
    }
  }
  cout << "-1 -1 -1";
}

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

  solve(n, y);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

void solve(int n, int y) {
  int max = y / 10000;
  for (int i = y; i >= 0; i--) {
    for (int j = 0; j <= 2000; j++) {
      if (i + j > n || i * 10000 + j * 5000 > y)
        break;
      for (int k = 0; k <= 2000; k++) {
        int sum = i * 10000 + j * 5000 + k * 1000;
        int num = i + j + k;
        if (sum > y || num > n)
          break;
        if (sum == y && num == n) {
          cout << i << " " << j << " " << k << endl;
          return;
        }
      }
    }
  }
  cout << "-1 -1 -1";
}

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

  solve(n, y);
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
// #include <random>
// #include <unordered_set>
#include <complex>
using namespace std;
int main() {
  long long n, y, i, j, k;
  cin >> n >> y;
  for (k = 0; k <= y / 1000; k++)
    for (j = 0; j <= (y - (k * 1000)) / 5000; j++)
      for (i = 0; i <= (y - (k * 1000) - (j * 5000)) / 1000; i++)
        if (((i + j + k) == n) and
            (((i * 10000) + (j * 5000) + (k * 1000)) == y)) {
          cout << i << " " << j << " " << k;
          system("pause");
          return 0;
        }
  cout << "-1 -1 -1";
  system("pause");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
// #include <random>
// #include <unordered_set>
#include <complex>
using namespace std;
int main() {
  long long n, y, i, j, k;
  cin >> n >> y;
  for (i = 0; i <= n; i++) {
    if ((i * 10000) > y)
      break;
    //     if((i*10000+(n-i)*5000)<y) continue;
    for (j = 0; j <= n - i; j++) {
      k = n - i - j;

      if (((i * 10000) + (j * 5000) + (k * 1000)) == y) {
        cout << i << " " << j << " " << k;
        system("pause");
        return 0;
      }

      if (((i * 10000) + (j * 5000) + (k * 1000)) > y)
        break;
    }
  }
  cout << "-1 -1 -1";
  system("pause");
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Y;
  cin >> N >> Y;
  rep(i, N + 1) {
    rep(j, N + 1) {
      rep(k, N + 1) {
        if (i + j + k != N)
          continue;
        if (i * 10000 + j * 5000 + k * 1000 == Y) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Y;
  cin >> N >> Y;
  rep(i, N + 1) {
    REP(j, 0, N - i) {
      REP(k, 0, N - (i + j)) {
        if (i + j + k != N)
          continue;
        if (i * 10000 + j * 5000 + k * 1000 == Y) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int n, yen;
  cin >> n >> yen;
  int flag = 0, a, b, c;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if ((10000 * i + 5000 * j + 1000 * k) == yen && i + j + k == n) {
          flag = 1;
          a = i;
          b = j;
          c = k;
        }
      }
    }
  }
  if (flag == 0)
    cout << "-1 -1 -1" << '\n';
  else
    cout << a << " " << b << " " << c << " " << '\n';
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int n, yen;
  cin >> n >> yen;
  int flag = 0, a, b, c;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; i + j <= n; j++) {
      if ((10000 * i + 5000 * j + 1000 * (n - i - j)) == yen) {
        flag = 1;
        a = i;
        b = j;
        c = (n - i - j);
      }
    }
  }
  if (flag == 0)
    cout << "-1 -1 -1" << '\n';
  else
    cout << a << " " << b << " " << c << " " << '\n';
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n, y;
  cin >> n >> y;
  int n1, n2, n3;
  n1 = 0;
  n2 = 0;
  n3 = 0;
  for (int i = 0; i < n + 1; ++i) {
    for (int j = 0; j < n + 1; ++j) {
      for (int k = 0; k < n + 1; ++k) {
        if (i * 10000 + j * 5000 + k * 1000 == y && i + j + k == n) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n, y;
  cin >> n >> y;
  int n1, n2, n3;
  n1 = 0;
  n2 = 0;
  n3 = 0;
  for (int i = 0; i < n + 1; ++i) {
    for (int j = 0; j < n + 1 - i; ++j) {
      for (int k = 0; k < n + 1 - i - j; ++k) {
        if (i * 10000 + j * 5000 + k * 1000 == y && i + j + k == n) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  long long int Y;
  cin >> N >> Y;
  int sum = Y / 1000;
  for (int x = 0; x < N + 1; x++) {
    for (int y = 0; y < N + 1; y++) {
      for (int z = 0; z < N + 1; z++) {
        if (x * 1 + y * 5 + z * 10 == sum && x + y + z == N) {
          cout << z << " " << y << " " << x << endl;
          goto END;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
END:

  return 0;
}

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

int main() {
  int N;
  long long int Y;
  cin >> N >> Y;
  int sum = Y / 1000;
  for (int x = N; x >= 0; x--) {
    for (int y = N - x; y >= 0; y--) {
      for (int z = N - (x + y); z >= 0; z--) {
        if (x * 1 + y * 5 + z * 10 == sum && x + y + z == N) {
          cout << z << " " << y << " " << x << endl;
          goto END;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
END:

  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
int main() {
  int N, Y;
  cin >> N >> Y;
  int money[3] = {10000, 5000, 1000};
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= N; k++) {
        if (i + j + k != N)
          continue;
        if (i * money[0] + j * money[1] + k * money[2] == Y) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
int main() {
  int N, Y;
  cin >> N >> Y;
  int money[3] = {10000, 5000, 1000};
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      int k = N - i - j;
      if (i * money[0] + j * money[1] + k * money[2] == Y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; i++) {
    if (10000 * i > y)
      break;
    for (int j = 0; j <= n; j++) {
      if (10000 * i + 5000 * j > y)
        break;
      for (int k = 0; k <= n; k++) {
        if (10000 * i + 5000 * j + 1000 * k > y)
          break;
        if (i + j + k == n && y == 10000 * i + 5000 * j + 1000 * k) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j + i <= n; j++) {
      if (y == 10000 * i + 5000 * j + 1000 * (n - i - j)) {
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

  if (Y > 20000000 || Y < 1000 || (Y % 1000) != 0) {
    cout << "-1 -1 -1";
    return 0;
  }

  int x = 0, y = 0, z = 0;

  for (x = 0; x < N + 1; x++) {
    for (y = 0; y < N + 1; y++) {
      for (z = 0; z < N + 1; z++) {
        if ((x + y + z) == N && 10000 * x + 5000 * y + 1000 * z == Y) {
          cout << x << " " << y << " " << z << endl;
          return 0;
        }
      }
    }
  }

  cout << "-1 -1 -1";
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

  if (Y > 20000000 || Y < 1000 || (Y % 1000) != 0) {
    cout << "-1 -1 -1";
    return 0;
  }

  int x = 0, y = 0, z = 0;

  for (x = 0; x < N + 1; x++) {
    for (y = 0; y < N + 1; y++) {
      int z = N - x - y;
      if (10000 * x + 5000 * y + 1000 * z == Y && z >= 0) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1";
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, Y;
  cin >> N >> Y;

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      for (int k = 0; k <= N; ++k) {
        if (Y == i * 10000 + j * 5000 + k * 1000 && i + j + k == N) {
          cout << i << " " << j << " " << k << " " << endl;
          return 0;
        }
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
}

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

int main() {
  long long N, Y;
  cin >> N >> Y;

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j + i <= N; ++j) {
      int k = N - i - j;
      if (Y == i * 10000 + j * 5000 + k * 1000) {
        cout << i << " " << j << " " << k << " " << endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  long long n, sum;
  scanf("%lld%lld", &n, &sum);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if (i * 1000 + 5000 * j + 10000 * k == sum && i + j + k == n) {
          cout << k << " " << j << " " << i << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1\n";
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  long long n, sum;
  scanf("%lld%lld", &n, &sum);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n - i; j++) {
      for (int k = 0; k <= n - i - j; k++) {
        if (i * 1000 + 5000 * j + 10000 * k == sum && i + j + k == n) {
          cout << k << " " << j << " " << i << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1\n";
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long n, y;
void solve() {
  long long x1, x2, x3, tag = 0;
  for (x1 = max(n, y / 10000); x1 >= 0; x1--) {
    for (x2 = max(n - x1, (y - x1 * 10000) / 5000); x2 >= 0; x2--) {

      for (x3 = max(n - x1 - x2, (y - x1 * 10000 - x2 * 5000) / 1000); x3 >= 0;
           x3--)
        if (x1 + x2 + x3 == n) {
          if (x1 * 10000 + x2 * 5000 + x3 * 1000 == y) {
            tag = 1;
            break;
          }
        }
      if (tag)
        break;
    }
    if (tag)
      break;
  }
  if (tag)
    cout << x1 << " " << x2 << " " << x3;
  else
    cout << "-1 -1 -1";
  cout << endl;
}
int main() {
  while (cin >> n >> y)
    solve();
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, y;
void solve() {
  long long x1, x2, x3, tag = 0;
  for (x1 = min(n, y / 10000); x1 >= 0; x1--) {
    for (x2 = min(n - x1, (y - x1 * 10000) / 5000); x2 >= 0; x2--) {
      for (x3 = min(n - x1 - x2, (y - x1 * 10000 - x2 * 5000) / 1000); x3 >= 0;
           x3--)
        if (x1 + x2 + x3 == n) {
          if (x1 * 10000 + x2 * 5000 + x3 * 1000 == y) {
            tag = 1;
            break;
          }
        }
      if (tag)
        break;
    }
    if (tag)
      break;
  }
  if (tag)
    cout << x1 << " " << x2 << " " << x3;
  else
    cout << "-1 -1 -1";
  cout << endl;
}
int main() {
  while (cin >> n >> y)
    solve();
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, y;

  while (scanf("%d%d", &n, &y) == 2) {
    int a = -1, b = -1, c = -1;
    bool found = false;

    for (int i = 0; i <= n && !found; i++) {
      for (int j = 0; j <= n && !found; j++) {
        for (int k = 0; k <= n && !found; k++) {
          if (i + j + k == n && i * 10000 + j * 5000 + k * 1000 == y)
            a = i, b = j, c = k, found = true;
        }
      }
    }

    printf("%d %d %d\n", a, b, c);
  }

  return 0;
}


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

int main() {
  int n, y;

  while (scanf("%d%d", &n, &y) == 2) {
    int a = -1, b = -1, c = -1;
    bool found = false;

    for (int i = 0; i <= n && !found; i++) {
      for (int j = 0; j <= n - i && !found; j++) {
        int k = n - i - j;
        if (i * 10000 + j * 5000 + k * 1000 == y)
          a = i, b = j, c = k, found = true;
      }
    }

    printf("%d %d %d\n", a, b, c);
  }

  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0)
    cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back())
      cout << " ";
  }
  cout << endl;
}
template <class T> void print(vector<vector<T>> &df) {
  for (auto &vec : df) {
    print(vec);
  }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 1001001001;

int bills[3] = {10000, 5000, 1000};

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

  rep(i, N + 1) {
    rep(j, N + 1) {
      rep(k, N + 1) {
        if (i + j + k != N)
          continue;
        if (bills[0] * i + bills[1] * j + bills[2] * k == Y) {
          print(i, j, k);
          return 0;
        }
      }
    }
  }

  print(-1, -1, -1);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0)
    cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back())
      cout << " ";
  }
  cout << endl;
}
template <class T> void print(vector<vector<T>> &df) {
  for (auto &vec : df) {
    print(vec);
  }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 1001001001;

int bills[3] = {10000, 5000, 1000};

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

  rep(i, N + 1) {
    rep(j, N + 1) {
      int k = N - (j + i);
      if (k < 0)
        continue;
      if (bills[0] * i + bills[1] * j + bills[2] * k == Y) {
        print(i, j, k);
        return 0;
      }
    }
  }

  print(-1, -1, -1);

  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[]) {
  // insert code here...

  int n, y;

  cin >> n >> y;

  int tmp = 0;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        tmp = 10000 * i + 5000 * j + 1000 * k;
        if ((tmp == y) && (i + j + k == n)) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}


Fixed submission:
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[]) {
  // insert code here...

  int n, y;

  cin >> n >> y;

  int tmp = 0;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n - i; j++) {
      for (int k = 0; k <= n - i - j; k++) {
        tmp = 10000 * i + 5000 * j + 1000 * k;
        if ((tmp == y) && (i + j + k == n)) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <ctype.h>
#include <stdio.h>
struct money {
  int ans, m;
} a[3] = {{0, 10000}, {0, 5000}, {0, 1000}};

inline int read() {
  int x = 0;
  bool f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    if (ch == '-')
      f = 0;
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return (f) ? x : -x;
}

inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + 48);
}

int main() {
  int n = read(), x = read();
  if (n * a[0].m < x) {
    printf("-1 -1 -1\n");
    return 0;
  }
  if (x % a[0].m == 0 && x / a[0].m == n) {
    printf("%d 0 0\n", x / a[0].m);
    return 0;
  }
  if (x % a[1].m == 0 && x / a[1].m == n) {
    printf("0 %d 0\n", x / a[1].m);
    return 0;
  }
  if (x % a[2].m == 0 && x / a[2].m == n) {
    printf("0 0 %d\n", x / a[2].m);
    return 0;
  }
  for (int i = 0; i <= x / 10000; ++i) {
    for (int j = 0; j <= x / 5000; ++j) {
      for (int k = 1; k <= x / 1000; ++k) {
        if (i * 10000 + j * 5000 + k * 1000 == x && i + j + k == n) {
          printf("%d %d %d\n", i, j, k);
          return 0;
        }
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}

Fixed submission:
#include <ctype.h>
#include <stdio.h>
struct money {
  int ans, m;
} a[3] = {{0, 10000}, {0, 5000}, {0, 1000}};

inline int read() {
  int x = 0;
  bool f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    if (ch == '-')
      f = 0;
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return (f) ? x : -x;
}

inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + 48);
}

int main() {
  int n = read(), x = read();
  if (n * a[0].m < x) {
    printf("-1 -1 -1\n");
    return 0;
  }
  if (x % a[0].m == 0 && x / a[0].m == n) {
    printf("%d 0 0\n", x / a[0].m);
    return 0;
  }
  if (x % a[1].m == 0 && x / a[1].m == n) {
    printf("0 %d 0\n", x / a[1].m);
    return 0;
  }
  if (x % a[2].m == 0 && x / a[2].m == n) {
    printf("0 0 %d\n", x / a[2].m);
    return 0;
  }
  for (int i = 0; i <= x / 10000; ++i) {
    for (int j = 0; j <= x / 5000; ++j) {
      int k = n - i - j;
      if (i * 10000 + j * 5000 + k * 1000 == x && k >= 0) {
        printf("%d %d %d\n", i, j, k);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}