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

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

string solve(long long N, long long Y) {
  string ans = "-1 -1 -1";
  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N - x; y++) {
      int z = N - (x + y);
      if (10'000 * x + 5'000 * y + 1'000 * z == Y)
        ans = to_string(x) + " " + to_string(y) + " " + to_string(z);
    }
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long Y;
  scanf("%lld", &Y);
  solve(N, Y);
  return 0;
}


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

void solve(long long N, long long Y) {
  string ans = "-1 -1 -1";
  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N - x; y++) {
      int z = N - (x + y);
      if (10'000 * x + 5'000 * y + 1'000 * z == Y)
        ans = to_string(x) + " " + to_string(y) + " " + to_string(z);
    }
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long Y;
  scanf("%lld", &Y);
  solve(N, Y);
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
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 q = 0; q <= n; q++) {
        if (10000 * i + 5000 * j + 1000 * q == y and i + j + q == n) {
          cout << i << " " << j << " " << q;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}

Fixed submission:
#include <iostream>
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 q = 0; q <= n - i - j; q++) {
        if (10000 * i + 5000 * j + 1000 * q == y and i + j + q == n) {
          cout << i << " " << j << " " << q;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main() {

  ll n, y;
  cin >> n;
  cin >> y;
  int aa = -1, bb = -1, cc = -1;

  for (int a = 0; a <= n; ++a) {
    for (int b = 0; b <= n; ++b) {
      if (a + b > n)
        break;
      int c = n - a - b;

      if (a * 10000 + b * 5000 + c * 1000 == y) {
        cout << a << " " << b << " " << c << endl;
        return 1;
      }
    }
  }

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

Fixed submission:
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main() {

  ll n, y;
  cin >> n;
  cin >> y;
  int aa = -1, bb = -1, cc = -1;

  for (int a = 0; a <= n; ++a) {
    for (int b = 0; b <= n; ++b) {
      if (a + b > n)
        break;
      int c = n - a - b;

      if (a * 10000 + b * 5000 + c * 1000 == y) {
        cout << a << " " << b << " " << c << 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, Y;
  cin >> N >> Y;
  int higuchi, noguchi, yukichi;

  /*
    yukichi+noguchi+higuchi = N
    10000yukichi+5000noguchi+1000higuchi = Y
    N =
  */

  for (int noguchi = 0; noguchi <= N; noguchi++) {
    for (int higuchi = 0; higuchi <= N; higuchi++) {
      for (int yukichi = 0; yukichi <= N; yukichi++) {
        int sum = 10000 * yukichi + 5000 * higuchi + 1000 * noguchi;
        if (sum == Y && noguchi + yukichi + higuchi == N) {
          cout << yukichi << " " << higuchi << " " << noguchi << endl;
          return 0;
        }
      }
    }
  }

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

  return 0;
}


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

int main() {
  int N, Y;
  cin >> N >> Y;
  int higuchi, noguchi, yukichi;

  /*
    yukichi+noguchi+higuchi = N
    10000yukichi+5000noguchi+1000higuchi = Y
    N =
  */

  for (int higuchi = 0; higuchi <= N; higuchi++) {
    for (int yukichi = 0; yukichi <= N; yukichi++) {
      int noguchi = N - higuchi - yukichi;
      int sum = 10000 * yukichi + 5000 * higuchi + 1000 * noguchi;
      if (sum == Y && noguchi + yukichi + higuchi == N && noguchi >= 0) {
        cout << yukichi << " " << higuchi << " " << noguchi << 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;
using LL = int64_t;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  m /= 1000;
  for (int i = 0; i * 10 <= m; i++) {
    for (int j = 0; j * 5 + i * 10 <= m; j++) {
      for (int k = 0; k + j * 5 + i * 10 <= m; k++) {
        if (k + j * 5 + i * 10 == m && i + j + k == n) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  m /= 1000;
  for (int i = 0; i * 10 <= m && i <= n; i++) {
    for (int j = 0; j * 5 + i * 10 <= m && i + j <= n; j++) {
      for (int k = 0; k + j * 5 + i * 10 <= m && i + j + k <= n; k++) {
        if (k + j * 5 + i * 10 == m && i + j + k == n) {
          cout << i << " " << j << " " << k << endl;
          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 = 0, Y = 0;
  int a = -1, b = -1, c = -1;
  int i, j, k;
  cin >> N >> Y;
  for (i = 0; i <= N; i++) {
    for (j = 0; j <= N; j++) {
      for (k = 0; k <= N; k++) {
        if (i * 10000 + j * 5000 + k * 1000 == Y && i + j + k == N) {
          a = i;
          b = j;
          c = k;
          break;
        }
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0, Y = 0;
  int a = -1, b = -1, c = -1;
  int i, j, k;
  cin >> N >> Y;
  for (i = 0; i <= N; i++) {
    for (j = 0; j <= (N - i); j++) {
      for (k = 0; k <= (N - (i + j)); k++) {
        if (i * 10000 + j * 5000 + k * 1000 == Y && i + j + k == N) {
          a = i;
          b = j;
          c = k;
          break;
        }
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}
Problem p03471 (C++)

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

#include <bitset>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <stack>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int> Pii;

#define pi 3.141592653589793
#define mod 1000000007

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

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

#include <bitset>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <stack>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int> Pii;

#define pi 3.141592653589793
#define mod 1000000007

int main() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      int k = n - i - j;
      if (10000 * i + 5000 * j + 1000 * k == y && k >= 0) {
        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;

typedef long long int LL;
typedef unsigned long long uLL;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 100005;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

LL x = 10000, y = 5000, z = 1000;

int main(int argc, char const *argv[]) {
  LL n, val;
  cin >> n >> val;
  for (LL i = 0; i <= n && x * i <= val; i++) {
    for (LL j = 0; j <= n && (x * i + y * j <= val); j++) {
      for (LL k = 0; k <= n && (x * i + y * j + z * k <= val); k++) {
        if (x * i + y * j + z * k == val && (i + j + k == n)) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


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

typedef long long int LL;
typedef unsigned long long uLL;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 100005;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

LL x = 10000, y = 5000, z = 1000;

int main(int argc, char const *argv[]) {
  LL n, val;
  cin >> n >> val;
  for (LL i = 0; i <= n && x * i <= val; i++) {
    for (LL j = 0; j <= n && (x * i + y * j <= val); j++) {
      LL tot = x * i + y * j;
      if (tot > val)
        break;
      if (tot == val && (i + j == n)) {
        cout << i << " " << j << " " << 0 << endl;
        return 0;
      }
      LL rem = val - tot;
      if (rem < 0)
        break;
      if (rem % 1000 == 0) {
        LL k = rem / 1000;
        if (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>
#include <iostream>
using namespace std;

int N;
int Y;

void input() {
  cin >> N;
  cin >> Y;
}

int main() {
  input();
  int n1000 = 0;
  int n5000 = 0;
  int n10000 = 0;
  int diff = 0;

  // 一番少ない枚数で算出
  n10000 = Y / 10000;
  n5000 = (Y - n10000 * 10000) / 5000;
  n1000 = (Y - n10000 * 10000 - n5000 * 5000) / 1000;

  if ((n10000 + n5000 + n1000) == N) {
    // 何もしない
  } else if ((n10000 + n5000 + n1000) > N) {
    n10000 = -1;
    n5000 = -1;
    n1000 = -1;
  } else {
    diff = N - (n10000 + n5000 + n1000);

    while (1) {
      // 最優先 5000 -> 1000 * 5
      if (n5000 > 0 && diff >= 4) {
        n5000--;
        n1000 += 5;
      } else if (n10000 > 0 && diff >= 1) {
        n10000--;
        n5000 += 2;
      }

      diff = N - (n10000 + n5000 + n1000);
      if (diff == 0 || diff < 0) {
        break;
      }
    }
  }

  cout << n10000 << " " << n5000 << " " << n1000 << endl;
  return 0;
}

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

int N;
int Y;

void input() {
  cin >> N;
  cin >> Y;
}

int main() {
  input();
  int n1000 = 0;
  int n5000 = 0;
  int n10000 = 0;
  int diff = 0;

  // 一番少ない枚数で算出
  n10000 = Y / 10000;
  n5000 = (Y - n10000 * 10000) / 5000;
  n1000 = (Y - n10000 * 10000 - n5000 * 5000) / 1000;

  if ((n10000 + n5000 + n1000) == N) {
    // 何もしない
  } else if ((n10000 + n5000 + n1000) > N) {
    n10000 = -1;
    n5000 = -1;
    n1000 = -1;
  } else {
    diff = N - (n10000 + n5000 + n1000);

    while (1) {
      // 最優先 5000 -> 1000 * 5
      if (n5000 > 0 && diff >= 4) {
        n5000--;
        n1000 += 5;
      } else if (n10000 > 0 && diff >= 1) {
        n10000--;
        n5000 += 2;
      } else {
        n10000 = -1;
        n5000 = -1;
        n1000 = -1;
        break;
      }

      diff = N - (n10000 + n5000 + n1000);
      if (diff == 0 || diff < 0) {
        break;
      }
    }
  }

  cout << n10000 << " " << n5000 << " " << n1000 << endl;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char *argv[]) {
  int N;
  LL Y;
  cin >> N >> Y;
  Y /= 1000;
  int x, y, z;
  for (x = 0; x <= N; x++) {
    for (y = 0; y <= N; y++) {
      for (z = 0; z <= N; z++) {
        if (x + y + z == N && 10 * x + 5 * y + z == Y) {
          cout << x << " " << y << " " << z << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char *argv[]) {
  int N;
  LL Y;
  cin >> N >> Y;
  Y /= 1000;
  int x, y, z;
  for (x = 0; x <= N; x++) {
    for (y = 0; y <= N; y++) {
      z = N - x - y;
      if (z >= 0) {
        if (10 * x + 5 * y + z == Y) {
          cout << x << " " << y << " " << z << endl;
          return 0;
        }
      }
    }
  }
  for (y = 0; y <= N; y++) {
    for (z = 0; z <= N; z++) {
      x = N - y - z;
      if (x >= 0) {
        if (10 * x + 5 * y + z == Y) {
          cout << x << " " << y << " " << z << endl;
          return 0;
        }
      }
    }
  }
  for (x = 0; x <= N; x++) {
    for (z = 0; z <= N; z++) {
      y = N - x - z;
      if (y >= 0) {
        if (10 * x + 5 * y + z == Y) {
          cout << x << " " << y << " " << z << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  long long n, a;
  cin >> n >> a;
  for (int i = 0; i <= a / 10000; i++) {
    for (int j = 0; j <= a / 5000; j++) {
      for (int l = 0; l <= a / 1000; l++) {
        if ((i * 10000 + j * 5000 + l * 1000) == a && (i + j + l) == n) {
          cout << i << " " << j << " " << l << endl;
          system("pause");
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  system("pause");
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long n, a;
  cin >> n >> a;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n - i; j++) {
      if ((i * 10000 + j * 5000 + (n - i - j) * 1000) == a) {
        cout << i << " " << j << " " << n - i - j << endl;
        system("pause");
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  system("pause");
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int N, Y;
int yen[3] = {10000, 5000, 1000};

void dfs(int depth, int sum, int cnt[3]) {
  if (depth == 0) {
    if (sum == Y) {
      cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
      exit(0);
    }
    return;
  }

  rep(i, 3) {
    int tmp = sum;
    tmp += yen[i];
    cnt[i]++;
    dfs(depth - 1, tmp, cnt);
    cnt[i]--;
  }
}

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

  int cnt[3] = {0};

  // dfs(N, 0, cnt);

  rep(i, N + 1) {
    rep(j, N + 1) {
      if (i + j > N)
        continue;
      rep(k, N + 1) {
        if (i + j + k != N)
          continue;
        if (Y == yen[0] * i + yen[1] * j + yen[2] * k) {
          cout << i << " " << j << " " << k << endl;
          exit(0);
        }
      }
    }
  }

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

Fixed submission:
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int N, Y;
int yen[3] = {10000, 5000, 1000};

void dfs(int depth, int sum, int cnt[3]) {
  if (depth == 0) {
    if (sum == Y) {
      cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
      exit(0);
    }
    return;
  }

  rep(i, 3) {
    int tmp = sum;
    tmp += yen[i];
    cnt[i]++;
    dfs(depth - 1, tmp, cnt);
    cnt[i]--;
  }
}

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

  int cnt[3] = {0};

  // dfs(N, 0, cnt);

  rep(i, N + 1) {
    rep(j, N + 1) {
      if (i + j > N)
        continue;
      if (yen[2] * (N - i - j) == Y - yen[0] * i - yen[1] * j) {
        cout << i << " " << j << " " << N - i - j << endl;
        exit(0);
      }
    }
  }

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

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;
const double eps = 1e-6;

int n, y;

int main() {
  scanf("%d%d", &n, &y);
  y /= 1000;

  for (int i = 0; i <= n && i <= y / 10; i++)
    for (int j = 0; j <= n && j <= (y - 10 * i) / 5; j++)
      for (int k = 0; k <= n && k <= y - 10 * i - 5 * j; k++)
        if (10 * i + 5 * j + k == y && i + j + k == n) {
          printf("%d %d %d\n", i, j, k);
          return 0;
        }

  puts("-1 -1 -1");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;
const double eps = 1e-6;

int n, y;

int main() {
  scanf("%d%d", &n, &y);
  y /= 1000;

  for (int i = 0; i <= n && i <= y / 10; i++)
    for (int j = 0; j <= n && j <= (y - 10 * i) / 5; j++) {
      int k = y - 10 * i - 5 * j;
      if (i + j + k == n) {
        printf("%d %d %d\n", i, j, k);
        return 0;
      }
    }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long int ll;
typedef unsigned long long ull;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef pair<ll, ll> P;

int main() {
  int n, y;
  cin >> n >> y;
  rep(i, n + 1) rep(k, n + 1) rep(t, n + 1) {
    if ((ll)10000 * i + 5000 * k + 1000 * t != y)
      continue;
    if (i + k + t == n) {
      cout << i << " " << k << " " << t << endl;
      return 0;
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long int ll;
typedef unsigned long long ull;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef pair<ll, ll> P;

int main() {
  int n, y;
  cin >> n >> y;
  rep(i, n + 1) rep(k, n + 1) {
    int t = n - i - k;
    if ((ll)10000 * i + 5000 * k + 1000 * t != y || t < 0)
      continue;
    if (i + k + t == n) {
      cout << i << " " << k << " " << t << endl;
      return 0;
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <climits>
#include <ctime>
#include <deque>
#include <exception>
#include <iomanip>
#include <iostream>/*{{{*/
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/time.h>
#include <vector>
using namespace std;
#define rep_n(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) rep_n(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define ci1(a) cin >> a
#define ci2(a, b) cin >> a >> b
#define ci3(a, b, c) cin >> a >> b >> c
#define ci4(a, b, c, d) cin >> a >> b >> c >> d
#define co1(a) cout << a << endl;
#define co2(a, b) cout << a << " " << b << endl;
#define co3(a, b, c) cout << a << " " << b << " " << c << endl;
#define co4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
typedef long long ll; /*}}}*/

int main() {
  int n, y;
  ci2(n, y);

  int a100, a50, a10, flag = 0;

  for (a100 = 0; a100 <= n; a100++) {
    for (a50 = 0; a50 <= n; a50++) {
      for (a10 = 0; a10 <= n; a10++) {
        if (a100 + a50 + a10 == n) {
          if (y == 10000 * a100 + 5000 * a50 + 1000 * a10) {
            printf("%d %d %d\n", a100, a50, a10), flag = 1;
            goto LABEL;
          }
        }
      }
    }
  }
LABEL:
  if (flag == 0)
    printf("-1 -1 -1");
}


Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <climits>
#include <ctime>
#include <deque>
#include <exception>
#include <iomanip>
#include <iostream>/*{{{*/
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/time.h>
#include <vector>
using namespace std;
#define rep_n(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) rep_n(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define ci1(a) cin >> a
#define ci2(a, b) cin >> a >> b
#define ci3(a, b, c) cin >> a >> b >> c
#define ci4(a, b, c, d) cin >> a >> b >> c >> d
#define co1(a) cout << a << endl;
#define co2(a, b) cout << a << " " << b << endl;
#define co3(a, b, c) cout << a << " " << b << " " << c << endl;
#define co4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
typedef long long ll; /*}}}*/

int main() {
  int n, y;
  ci2(n, y);

  int a100, a50, a10, flag = 0;

  for (a100 = 0; a100 <= n; a100++) {
    for (a50 = 0; a50 <= (n - a100); a50++) {
      for (a10 = 0; a10 <= (n - a100 - a50); a10++) {
        if (a100 + a50 + a10 == n) {
          if (y == 10000 * a100 + 5000 * a50 + 1000 * a10) {
            printf("%d %d %d\n", a100, a50, a10), flag = 1;
            goto LABEL;
          }
        }
      }
    }
  }
LABEL:
  if (flag == 0)
    printf("-1 -1 -1");
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <string>

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) {
          if (10000 * i + 5000 * j + 1000 * k == y) {
            cout << i << " " << j << " " << k << endl;
            goto Exit;
          }
        }
      }
    }
  }
  cout << "-1"
       << " "
       << "-1"
       << " "
       << "-1" << endl;
Exit:;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <string>

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++) {
      int k = (y - (10000 * i + 5000 * j)) / 1000;
      if (i + j + k == n && k >= 0) {
        cout << i << " " << j << " " << k << endl;
        goto Exit;
      }
    }
  }
  cout << "-1"
       << " "
       << "-1"
       << " "
       << "-1" << endl;
Exit:;
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)

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

  ll n, y;
  cin >> n >> y;
  rep(i, n + 1) {
    rep(j, n + 1) {
      rep(k, n + 1) {
        if (i + j + k == n and 10000 * i + 5000 * j + 1000 * k == y) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)

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

  ll n, y;
  cin >> n >> y;
  rep(i, n + 1) {
    rep(j, n + 1) {
      ll k = n - i - j;
      if (k >= 0 and 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 <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, N, Y, ii = -1, jj = -1, kk = -1, ans;
  cin >> N >> Y;
  for (i = 0; i <= N; i++) {
    for (j = 0; j <= N; j++) {
      for (k = 0; k <= N; k++) {
        if (i + j + k == N) {
          ans = 10000 * i + 5000 * j + 1000 * k;
          if (ans == Y) {
            ii = i;
            jj = j;
            kk = k;
          }
        }
      }
    }
  }
  cout << ii << " " << jj << " " << kk << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, N, Y, ii = -1, jj = -1, kk = -1, ans;
  cin >> N >> Y;
  for (i = 0; i <= N; i++) {
    for (j = 0; j <= N - i; j++) {
      k = N - i - j;
      ans = 10000 * i + 5000 * j + 1000 * k;
      if (ans == Y) {
        ii = i;
        jj = j;
        kk = k;
      }
    }
  }
  cout << ii << " " << jj << " " << kk << "\n";
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a = 10000, b = 5000, c = 1000;
  int n, y;
  bool flag = false;
  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 && (i * a + j * b + k * c) == y) {
          flag = true;
          cout << i << " " << j << " " << k << endl;
          break;
        }
      }
      if (flag)
        break;
    }
    if (flag)
      break;
  }
  if (!flag)
    cout << "-1 -1 -1" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a = 10000, b = 5000, c = 1000;
  int n, y;
  bool flag = false;
  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 && (i * a + j * b + k * c) == y) {
          flag = true;
          cout << i << " " << j << " " << k << endl;
          break;
        } else if (i + j + k > n)
          break;
      }
      if (flag)
        break;
    }
    if (flag)
      break;
  }
  if (!flag)
    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; j++)
      if ((N - i - j) >= 0 &&
          (10000 * i + 5000 * j + 1000 * (N - i - j)) == Y) {
        cout << i << " " << j << " " << N - i - j << endl;
        return 0;
      }

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

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

int main() {
  int N, S;
  int cnt = 0;
  cin >> N >> S;
  for (int X = 0; X < N + 1; X++) {
    for (int Y = 0; Y < N + 1 - X; Y++) {
      int Z = N - X - Y;
      if (10000 * X + 5000 * Y + 1000 * Z == S) {
        cnt += 1;
        cout << X << " " << Y << " " << Z << endl;
        exit(1);
      }
    }
  }

  if (cnt == 0)
    cout << "-1 -1 -1" << endl;

  return 0;
}

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

int main() {
  int N, S;
  int cnt = 0;
  cin >> N >> S;
  for (int X = 0; X < N + 1; X++) {
    for (int Y = 0; Y < N + 1 - X; Y++) {
      int Z = N - X - Y;
      if (10000 * X + 5000 * Y + 1000 * Z == S) {
        cnt += 1;
        cout << X << " " << Y << " " << Z << endl;
        return 0;
      }
    }
  }

  if (cnt == 0)
    cout << "-1 -1 -1" << endl;

  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
#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() {

  double N, Y;
  cin >> N >> Y;
  vector<double> M(3, 0);
  M[0] = 10000;
  M[1] = 5000;
  M[2] = 1000;

  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= (N - x); y++) {
      for (int z = 0; z <= (N - x - y); z++) {
        if (M[0] * z + M[1] * y + M[2] * x == Y && x + y + z == N) {
          cout << z << " " << y << " " << x << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
#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() {

  double N, Y;
  cin >> N >> Y;
  vector<double> M(3, 0);
  M[0] = 10000;
  M[1] = 5000;
  M[2] = 1000;

  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= (N - x); y++) {
      for (int z = N - x - y; z <= (N - x - y); z++) {
        if (M[0] * z + M[1] * y + M[2] * x == Y && x + y + z == N) {
          cout << z << " " << y << " " << x << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}
Problem p03471 (C++)

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

using namespace std;

void print(int i, int j, int k) { cout << i << " " << j << " " << k << endl; }

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)
          continue;
        if (i * 10000 + j * 5000 + k * 1000 == y) {
          print(i, j, k);
          goto end;
        }
      }
    }
  }
  print(-1, -1, -1);
end:
  return 0;
}

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

using namespace std;

void print(int i, int j, int k) { cout << i << " " << j << " " << k << endl; }

int main() {
  int n, y;

  cin >> n >> y;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j + i <= n; j++) {
      for (int k = 0; k + j + i <= n; k++) {
        if (i + k + j != n)
          continue;
        if (i * 10000 + j * 5000 + k * 1000 == y) {
          print(i, j, k);
          goto end;
        }
      }
    }
  }
  print(-1, -1, -1);
end:
  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;
  y /= 1000;
  for (int i = 0; i <= 2000; i++) {
    int flag1 = 0, flag2 = 0;
    for (int j = 0; j <= 2000; j++) {
      for (int k = 0; k <= 2000; k++) {
        int num = i * 10 + j * 5 + k;
        if (num == y && i + j + k == n) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
int n, y;
int main() {
  cin >> n >> y;
  y /= 1000;
  for (int i = 0; i <= 2000; i++) {
    int flag1 = 0, flag2 = 0;
    for (int j = 0; j <= 2000; j++) {
      for (int k = 0; k <= 2000; k++) {
        int num = i * 10 + j * 5 + k;
        if (num > y || i + j + k > n) {
          flag1 = 1;
          break;
        }
        if (num == 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 <iostream>
using namespace std;
int main() {
  int n, money;
  cin >> n >> money;
  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 + 1000 * k + 5000 * j == money) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, money;
  cin >> n >> money;
  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 + 1000 * k + 5000 * j == money) {
          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;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9 + 7
#define PI acos(-1.0)
#define ll long long

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N, Y;
  cin >> N >> Y;
  REP(i, N + 1) {
    REP(j, N + 1) {
      REP(k, N + 1) {
        if (Y == (10000 * i + 5000 * j + 1000 * k) && (i + j + k) == N) {
          cout << i << " " << j << " " << k << "\n";
          return 0;
        }
      }
    }
  }

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


Fixed submission:
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9 + 7
#define PI acos(-1.0)
#define ll long long

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N, Y;
  cin >> N >> Y;
  REP(i, N + 1) {
    REP(j, N + 1) {
      if (Y == (10000 * i + 5000 * j + 1000 * (N - i - j)) &&
          (N - i - j) >= 0) {
        cout << i << " " << j << " " << N - i - j << "\n";
        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;

int main() {
  int N, y;

  cin >> N >> y;

  for (int i = 0; i < 2001; i++) {
    for (int j = 0; j < 2001; j++) {
      for (int k = 0; k < 2001; k++) {
        if (y == 10000 * i + 5000 * j + 1000 * k && 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() {
  int N, y;

  cin >> N >> y;

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

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

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

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

void input(int &rnTrgSu, int &rnTrgKin) { cin >> rnTrgSu >> rnTrgKin; }

int searchMoney(int nTrgSu, int nTrgKin) {
  vector<int> cnvnMoney{10000, 5000, 1000};

  int nCalKin;
  int i, j;
  for (i = 0; i <= nTrgSu; i++) {
    for (j = 0; j <= (nTrgSu - i); j++) {
      nCalKin = nTrgKin;

      nCalKin -= cnvnMoney[0] * i;
      nCalKin -= cnvnMoney[1] * j;
      nCalKin -= cnvnMoney[2] * (nTrgSu - i - j);
      if (!nCalKin)
        break;
    }
    if (!nCalKin)
      break;
  }
  if (!nCalKin)
    cout << i << " " << j << " " << (nTrgSu - i - j) << endl;
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main() {
  int nTrgSu, nTrgKin;

  input(nTrgSu, nTrgKin);
  searchMoney(nTrgSu, nTrgKin);

  return 0;
}

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

void input(int &rnTrgSu, int &rnTrgKin) { cin >> rnTrgSu >> rnTrgKin; }

void searchMoney(int nTrgSu, int nTrgKin) {
  vector<int> cnvnMoney{10000, 5000, 1000};

  int nCalKin;
  int i, j;
  for (i = 0; i <= nTrgSu; i++) {
    for (j = 0; j <= (nTrgSu - i); j++) {
      nCalKin = nTrgKin;

      nCalKin -= cnvnMoney[0] * i;
      nCalKin -= cnvnMoney[1] * j;
      nCalKin -= cnvnMoney[2] * (nTrgSu - i - j);
      if (!nCalKin)
        break;
    }
    if (!nCalKin)
      break;
  }
  if (!nCalKin)
    cout << i << " " << j << " " << (nTrgSu - i - j) << endl;
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main() {
  int nTrgSu, nTrgKin;

  input(nTrgSu, nTrgKin);
  searchMoney(nTrgSu, nTrgKin);

  return 0;
}
Problem p03471 (C++)

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

int main() {
  int N;
  int Y;
  cin >> N >> Y;
  int pair[3] = {-1, -1, -1};
  for (int i = 0; i <= N; i++) {   // 10000円
    for (int j = 0; j <= N; j++) { // 5000円
      if (i + j > N) {
        continue;
      }
      for (int k = 0; k <= N; k++) { // 1000円
        if (i + j + k > N) {
          continue;
        }
        if (i + j + k == N) {
          if (i * 10000 + j * 5000 + k * 1000 == Y) {
            pair[0] = i;
            pair[1] = j;
            pair[2] = k;
            break;
          }
        }
      }
    }
  }
  cout << pair[0] << " " << pair[1] << " " << pair[2] << endl;
}


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

int main() {
  int N;
  int Y;
  cin >> N >> Y;
  int pair[3] = {-1, -1, -1};
  for (int i = 0; i <= N; i++) {   // 10000円
    for (int j = 0; j <= N; j++) { // 5000円
      if (i + j > N) {
        continue;
      }
      int k = N - i - j;
      if (k >= 0 && k <= N) {
        if (i * 10000 + j * 5000 + k * 1000 == Y) {
          pair[0] = i;
          pair[1] = j;
          pair[2] = k;
          break;
        }
      }
    }
  }
  cout << pair[0] << " " << pair[1] << " " << pair[2] << endl;
}
Problem p03471 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n, y;
  cin >> n >> y;
  y /= 1000;
  for (int i = 0; i <= y / 10; i++) {
    for (int j = 0; j <= (y - 10 * i) / 5; j++) {
      if (i + j + (y - 10 * i - 5 * j) == n) {
        cout << i << " " << j << " " << y - 10 * i - 5 * j << endl;
        return 1;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}

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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long;

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

  ll i, j;
  for (i = y / 10000; i >= 0; i--) {
    if (i > n)
      continue;
    for (j = (y - 10000 * i) / 5000; j >= 0; j++) {
      if (i + j > n)
        continue;
      if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }

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


Fixed submission:
#include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long;

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

  ll i, j;
  for (i = y / 10000; i >= 0; i--) {
    if (i > n)
      continue;
    for (j = (y - 10000 * i) / 5000; j >= 0; j--) {
      if (i + j > n)
        continue;
      if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }

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

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

int main() {
  int n, yen;
  cin >> n >> yen;
  yen = yen / 1000;

  int money_x = -1, money_y = -1, money_z = -1;

  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 ((10 * z) + (5 * y) + x == yen && x + y + z == n) {
          money_x = z;
          money_y = y;
          money_z = x;
          break;
        } else if ((10 * z) + (5 * y) + x > yen || x + y + z > n) {
          z = n + 1;
        }
      }
    }
  }

  cout << money_x << ' ' << money_y << ' ' << money_z << endl;

  return 0;
}

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

int main() {
  int n, yen;
  cin >> n >> yen;
  yen = yen / 1000;

  int money_x = -1, money_y = -1, money_z = -1;

  for (int x = 0; x <= n; ++x) {
    for (int y = 0; y <= n - x; ++y) {
      int z = n - x - y;
      if ((10 * x) + (5 * y) + z == yen) {
        money_x = x;
        money_y = y;
        money_z = z;
        break;
      }
    }
  }

  cout << money_x << ' ' << money_y << ' ' << money_z << endl;

  return 0;
}
Problem p03471 (C++)

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

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

  for (int32_t cnt_man = 0; cnt_man <= Y / 10000; cnt_man++) {
    for (int32_t cnt_gosen = 0; cnt_gosen <= Y / 5000; cnt_gosen++) {
      for (int32_t cnt_sen = 0; cnt_sen <= Y / 1000; cnt_sen++) {
        int32_t total_maisu = cnt_man + cnt_gosen + cnt_sen;
        int32_t total_money =
            cnt_man * 10000 + cnt_gosen * 5000 + cnt_sen * 1000;

        if (total_maisu > N || total_money > Y)
          break;

        if (total_maisu == N && total_money == Y) {
          cout << cnt_man << " " << cnt_gosen << " " << cnt_sen << endl;
          return 0;
        }
      }
    }
  }

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <string>
#include <vector>
using namespace std;

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

  for (int32_t cnt_man = 0;; cnt_man++) {
    if (cnt_man > N || cnt_man * 10000 > Y)
      break;

    for (int32_t cnt_gosen = 0;; cnt_gosen++) {
      if (cnt_man + cnt_gosen > N || cnt_man * 10000 + cnt_gosen * 5000 > Y)
        break;

      for (int32_t cnt_sen = 0;; cnt_sen++) {
        int32_t total_maisu = cnt_man + cnt_gosen + cnt_sen;
        int32_t total_money =
            cnt_man * 10000 + cnt_gosen * 5000 + cnt_sen * 1000;

        if (total_maisu > N || total_money > Y)
          break;

        if (total_maisu == N && total_money == Y) {
          cout << cnt_man << " " << cnt_gosen << " " << cnt_sen << endl;
          return 0;
        }
      }
    }
  }

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

  return 0;
}
Problem p03471 (C++)

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

using namespace std;

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

  for (int i = Y / 10000; i >= 0; i--)
    for (int j = (Y - i * 10000) / 5000; j >= 0; j--)
      for (int k = (Y - 10000 * i - 5000 * j) / 1000; k >= 0; 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;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int N, Y;
  cin >> N >> Y;
  for (int x = Y / 10000; x >= 0; x--)
    for (int y = (Y - x * 10000) / 5000; y >= 0; y--) {
      int z;
      z = N - x - y;
      if ((10000 * x + 5000 * y + 1000 * z) == Y) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}
Problem p03471 (C++)

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

using namespace std;

int main() {
  int N;
  int 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 == 10000 * i + 5000 * j + 1000 * k && N == i + j + k) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}


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

using namespace std;

int main() {
  int N;
  int 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 (Y == 10000 * i + 5000 * j + 1000 * k && N == i + j + k) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}