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

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

int main() {

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


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

int main() {

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};

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

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main() {
  ll n, y;
  cin >> n >> y;
  y /= 1000;
  for (int i = y / 10; i >= 0; i--) {
    for (int j = (y - i * 10) / 5; j >= 0; j--) {
      int k = y - 10 * i - 5 * j;
      if (i + j + k == n && 10 * i + 5 * j + 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;
#define ll long long int
int main() {
  ll n, y;
  cin >> n >> y;
  ll a[3] = {10000, 5000, 1000};
  ll ans[3] = {0};
  int f = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if ((i * a[0] + j * a[1] + k * a[2] == y) && f != 1 &&
            (i + j + k == n)) {
          ans[0] = i;
          ans[1] = j;
          ans[2] = k;
          // cout<<i<<" "<<j<<" "<<k;
          f = 1;
        }
      }
    }
  }
  if (f == 1)
    cout << ans[0] << " " << ans[1] << " " << ans[2];
  else
    cout << -1 << " " << -1 << " " << -1;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ll n, y;
  cin >> n >> y;
  ll a[3] = {10000, 5000, 1000};
  ll ans[3] = {0};
  int f = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      int k = n - i - j;
      if ((i * a[0] + j * a[1] + k * a[2] == y) && f != 1 && (i + j + k == n) &&
          (k >= 0)) {
        ans[0] = i;
        ans[1] = j;
        ans[2] = k;
        // cout<<i<<" "<<j<<" "<<k;
        f = 1;
      }
    }
  }
  if (f == 1)
    cout << ans[0] << " " << ans[1] << " " << ans[2];
  else
    cout << -1 << " " << -1 << " " << -1;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int m, n, k = 1;
  cin >> m >> n;
  int a = n / 1000;
  for (int x = 0; x <= m; x++) {
    for (int y = 0; y <= m; y++) {
      for (int z = 0; z <= m; z++) {
        if (x + y + z == m && 10 * x + 5 * y + z == a) {
          cout << x << ' ' << y << ' ' << z;
          k = 0;
          break;
        }
      }
      if (k == 0) {
        break;
      }
    }
    if (k == 0) {
      break;
    }
  }
  if (k) {
    cout << "-1" << ' ' << "-1" << ' ' << "-1";
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int m, n, k = 1;
  cin >> m >> n;
  int a = n / 1000;
  for (int x = m; x >= 0; x--) {
    for (int y = m - x; y >= 0; y--) {
      for (int z = m - x - z; z >= 0; z--) {
        if (x + y + z == m && 10 * x + 5 * y + z == a) {
          cout << x << ' ' << y << ' ' << z;
          k = 0;
          break;
        }
      }
      if (k == 0) {
        break;
      }
    }
    if (k == 0) {
      break;
    }
  }
  if (k) {
    cout << "-1" << ' ' << "-1" << ' ' << "-1";
  }
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N, Y;
  int A, B, C;
  int i, j, k;
  int flg = 0;

  cin >> N >> Y;

  for (i = 0; i <= N && flg == 0; i++) {
    for (j = 0; j <= N && flg == 0; j++) {
      for (k = 0; k <= N && flg == 0; k++) {
        if ((i * 10000 + j * 5000 + k * 1000 == Y) && (i + j + k == N)) {
          A = i;
          B = j;
          C = k;
          flg = 1;
        }
      }
    }
  }
  if (flg == 1) {
    cout << A << " " << B << " " << C << endl;
  } else {
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N, Y;
  int A, B, C;
  int i, j, k;
  int flg = 0;

  cin >> N >> Y;

  for (i = 0; i <= N && flg == 0; i++) {
    for (j = 0; j <= N && flg == 0; j++) {
      k = N - i - j;
      if (k >= 0 && (i * 10000 + j * 5000 + k * 1000 == Y)) {
        A = i;
        B = j;
        C = k;
        flg = 1;
      }
    }
  }
  if (flg == 1) {
    cout << A << " " << B << " " << C << endl;
  } else {
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
}
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 < (int)(n); i++)

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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n - i; j++) {
      int n1000 = n - i - j;
      if (10000 * i + 5000 * j + 1000 * n1000 == y) {
        cout << i << " " << j << " " << n1000 << 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, Y;
  cin >> N >> Y;
  int A, B, C;
  A = -1;
  B = -1;
  C = -1;
  // C=N-A-B;
  // int ans=0;

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


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

int main() {
  int N, Y;
  cin >> N >> Y;
  int A, B, C;
  A = -1;
  B = -1;
  C = -1;
  // C=N-A-B;
  // int ans=0;

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; i + j <= N; ++j) {
      int k = N - i - j;
      int ans = 10000 * i + 5000 * j + 1000 * k;
      if (ans == Y) {
        A = i;
        B = j;
        C = k;
        break;
      }
    }
  }
  cout << A << " " << B << " " << C << endl;
}
Problem p03471 (C++)

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

int main() {

  int n, y;

  cin >> n >> y;

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

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

  return 0;
}


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

int main() {

  int n, y;

  cin >> n >> y;

  for (int i = 0; 10000 * i <= y && i <= n; i++) {
    for (int j = 0; 10000 * i + 5000 * j <= y && i + j <= n; j++) {
      for (int k = 0; 10000 * i + 5000 * j + 1000 * k <= y && i + j + k <= n;
           k++) {
        if (10000 * i + 5000 * j + 1000 * k == 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, m, i, j, k, u, l1, l2, l3;
  scanf("%d%d", &n, &m);
  l1 = min(m / 1000, n);
  l2 = min(m / 5000, n);
  l3 = min(m / 10000, n);
  for (i = 0; i <= l1; i++) {
    for (j = 0; j <= l2; j++) {
      for (k = 0; k <= l3; k++) {
        if (i + j + k == n && i * 1000 + j * 5000 + k * 10000 == m) {
          printf("%d %d %d", k, j, i);
          return 0;
        }
      }
    }
  }
  printf("-1 -1 -1");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, u, l1, l2, l3;
  scanf("%d%d", &n, &m);
  l1 = min(m / 1000, n);
  l2 = min(m / 5000, n);
  l3 = min(m / 10000, n);
  for (i = 0; i <= l1; i++) {
    for (j = 0; j <= l2; j++) {
      k = n - i - j;
      if (k > l3 || k < 0)
        continue;
      if (i * 1000 + j * 5000 + k * 10000 == m) {
        printf("%d %d %d", k, j, i);
        return 0;
      }
    }
  }
  printf("-1 -1 -1");
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int n, y, 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 + j + k == n && 1000 * i + 5000 * j + 10000 * k == y) {
          printf("%d %d %d\n", k, j, i);
          return 0;
        }
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, y, i, j, k;
  cin >> n >> y;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= n; j++) {
      k = n - i - j;
      if (k >= 0 && 1000 * i + 5000 * j + 10000 * k == y) {
        printf("%d %d %d\n", k, j, i);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}
Problem p03471 (C++)

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

using namespace std;

int N;
int Y;

int main(void) {
  bool flag = true;
  cin >> N;
  cin >> Y;

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

  if (flag)
    cout << -1 << " " << -1 << " " << -1 << endl;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int N;
int Y;

int main(void) {
  bool flag = true;
  cin >> N;
  cin >> Y;

  for (int x = 0; Y - 10000 * x >= 0; x++) {
    for (int y = 0; Y - 10000 * x - 5000 * y >= 0; y++) {
      if ((Y - 10000 * x - 5000 * y) / 1000 == N - x - y && flag == true) {
        cout << x << " " << y << " " << N - x - y << endl;
        flag = false;
      }
    }
  }

  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;

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, Y;
  cin >> N >> Y;

  // x + y + z = N &&
  // 10000 * x + 5000 * y + 1000 * z == Y
  bool can_continue = true;
  for (int x = 0; x <= Y / 10000; x++) {
    if (x > N) {
      break;
    }
    int x_made = x * 10000;

    for (int y = 0; y <= Y / 5000; y++) {
      int y_made = x_made + y * 5000;
      if (y_made > Y || x + y > N) {
        break;
      }

      for (int z = 0; z <= Y / 1000; z++) {
        int z_made = y_made + z * 1000;
        if (z_made > Y || x + y + z > N) {
          break;
        } else if (z_made == Y && x + y + z == N) {
          printf("%d %d %d\n", x, y, z);
          can_continue = false;
        }
      }
      if (!can_continue) {
        break;
      }
    }
    if (!can_continue) {
      break;
    }
  }
  if (can_continue) {
    printf("%d %d %d\n", -1, -1, -1);
  }
}

int main() { answer1(); }


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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, Y;
  cin >> N >> Y;

  // x + y + z = N &&
  // 10000 * x + 5000 * y + 1000 * z == Y
  bool can_continue = true;
  for (int x = 0; x <= Y / 10000; x++) {
    if (x > N) {
      break;
    }
    int x_made = x * 10000;

    for (int y = 0; y <= Y / 5000; y++) {
      int y_made = x_made + y * 5000;
      if (y_made > Y || x + y > N) {
        break;
      }

      for (int z = 0; z <= Y / 1000; z++) {
        int z_made = y_made + z * 1000;
        if (z_made > Y || x + y + z > N) {
          break;
        } else if (z_made == Y && x + y + z == N) {
          printf("%d %d %d\n", x, y, z);
          can_continue = false;
        }
      }
      if (!can_continue) {
        break;
      }
    }
    if (!can_continue) {
      break;
    }
  }
  if (can_continue) {
    printf("%d %d %d\n", -1, -1, -1);
  }
}

void answer2() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, Y;
  cin >> N >> Y;

  // x + y + z = N &&
  // 10000 * x + 5000 * y + 1000 * z == Y
  bool can_continue = true;
  for (int x = 0; x <= Y / 10000; x++) {
    if (x > N) {
      break;
    }
    int x_made = x * 10000;

    for (int y = 0; y <= Y / 5000; y++) {
      int y_made = x_made + y * 5000;
      if (y_made > Y || x + y > N) {
        break;
      }

      int z = N - x - y;
      int z_made = y_made + z * 1000;
      if (z_made == Y) {
        printf("%d %d %d\n", x, y, z);
        can_continue = false;
        break;
      }
    }
    if (!can_continue) {
      break;
    }
  }
  if (can_continue) {
    printf("%d %d %d\n", -1, -1, -1);
  }
}

int main() {
  // answer1(); // 実行時間制限超過
  answer2();
}
Problem p03471 (C++)

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

#define IS_EVEN(a) (((a)&0x01) == 0)

int cmp(const void *a, const void *b) {
  return (*(const int *)b) - (*(const int *)a);
}

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

  int a, b, c;
  int a_max, b_max, c_max;
  // a+b+c=n
  // 10000*a + 5000*b + 1000*c = y

  a_max = y / 10000;
  b_max = y / 5000;
  c_max = y / 1000;
  for (int i = 0; i <= a_max; i++) {
    for (int j = 0; j <= b_max; j++) {
      for (int k = 0; k <= c_max; k++) {
        if (i * 10000 + j * 5000 + k * 1000 == y && i + j + k == n) {
          cout << i << " " << j << " " << k << endl;
          goto end;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
end:
  return 0;
}


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

#define IS_EVEN(a) (((a)&0x01) == 0)

int cmp(const void *a, const void *b) {
  return (*(const int *)b) - (*(const int *)a);
}

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

  int a, b, c;
  int a_max, b_max, c_max;
  // a+b+c=n
  // 10000*a + 5000*b + 1000*c = y

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

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

using namespace std;

int main() {
  int n, y;
  scanf("%d %d", &n, &y);
  int c1 = y / 10000;
  int c2 = y / 5000;
  int c3 = y / 1000;
  for (int i = 0; i <= c1; i++) {
    for (int j = 0; j <= c2; j++) {
      for (int k = 0; k <= c3; k++) {
        if (i + k + j == n) {
          int cur = i * 10000 + j * 5000 + k * 1000;
          if (cur == y) {
            printf("%d %d %d\n", i, j, k);
            return 0;
          }
        }
      }
    }
  }
  printf(" -1 -1 -1\n");
  return 0;
}

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

using namespace std;

int main() {
  int n, y;
  scanf("%d %d", &n, &y);
  int c1 = y / 10000;
  int c2 = y / 5000;
  int c3 = y / 1000;
  for (int i = 0; i <= c1; i++) {
    for (int j = 0; j <= c2; j++) {
      for (int k = 0; k <= c3; k++) {
        if (i + k + j == n) {
          int cur = i * 10000 + j * 5000 + k * 1000;
          if (cur == y) {
            printf("%d %d %d\n", i, j, k);
            return 0;
          }
        } else if (i + k + j > n) {
          break;
        }
      }
    }
  }
  printf(" -1 -1 -1\n");
  return 0;
}
Problem p03471 (C++)

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

int main() {
  int N, Y;
  cin >> N >> Y;
  int ans = -1;
  int ans2 = -1;
  int ans3 = -1;
  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) {
          ans = i;
          ans2 = j;
          ans3 = k;
        }
      }
    }
  }

  cout << ans << " " << ans2 << " " << ans3 << endl;
}

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

int main() {
  int N, Y;
  cin >> N >> Y;
  int ans = -1;
  int ans2 = -1;
  int ans3 = -1;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; i + j <= N; ++j) {
      int k = N - i - j;
      if (10000 * i + 5000 * j + 1000 * k == Y) {
        ans = i;
        ans2 = j;
        ans3 = k;
      }
    }
  }

  cout << ans << " " << ans2 << " " << ans3 << endl;
}
Problem p03471 (C++)

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

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

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

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

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<short, short> P;
int f[2005][20005];
P a[2005][20005];
void dp(int x, int y) {
  if (f[x][y])
    return;
  f[x][y] = -1;
  if (x == 1) {
    if (y == 10) {
      a[x][y].first = 1;
      f[x][y] = 1;
    }
    if (y == 5) {
      a[x][y].second = 1;
      f[x][y] = 1;
    }
    if (y == 1)
      f[x][y] = 1;
    return;
  }
  if (y > 10) {
    dp(x - 1, y - 10);
    if (f[x - 1][y - 10] > 0) {
      f[x][y] = 1;
      a[x][y] = a[x - 1][y - 10];
      a[x][y].first++;
      return;
    }
  }
  if (y > 5) {
    dp(x - 1, y - 5);
    if (f[x - 1][y - 5] > 0) {
      f[x][y] = 1;
      a[x][y] = a[x - 1][y - 5];
      a[x][y].second++;
      return;
    }
  }
  if (y > 1) {
    dp(x - 1, y - 1);
    if (f[x - 1][y - 1] > 0) {
      f[x][y] = 1;
      a[x][y] = a[x - 1][y - 1];
      return;
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  m /= 1000;
  dp(n, m);
  if (f[n][m] < 0)
    printf("-1 -1 -1\n");
  else
    printf("%d %d %d\n", a[n][m].first, a[n][m].second,
           n - a[n][m].first - a[n][m].second);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<short, short> P;
short f[2005][20005];
P a[2005][20005];
void dp(int x, int y) {
  if (f[x][y])
    return;
  f[x][y] = -1;
  if (x == 1) {
    if (y == 10) {
      a[x][y].first = 1;
      f[x][y] = 1;
    }
    if (y == 5) {
      a[x][y].second = 1;
      f[x][y] = 1;
    }
    if (y == 1)
      f[x][y] = 1;
    return;
  }
  if (y > 10) {
    dp(x - 1, y - 10);
    if (f[x - 1][y - 10] > 0) {
      f[x][y] = 1;
      a[x][y] = a[x - 1][y - 10];
      a[x][y].first++;
      return;
    }
  }
  if (y > 5) {
    dp(x - 1, y - 5);
    if (f[x - 1][y - 5] > 0) {
      f[x][y] = 1;
      a[x][y] = a[x - 1][y - 5];
      a[x][y].second++;
      return;
    }
  }
  if (y > 1) {
    dp(x - 1, y - 1);
    if (f[x - 1][y - 1] > 0) {
      f[x][y] = 1;
      a[x][y] = a[x - 1][y - 1];
      return;
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  m /= 1000;
  dp(n, m);
  if (f[n][m] < 0)
    printf("-1 -1 -1\n");
  else
    printf("%d %d %d\n", a[n][m].first, a[n][m].second,
           n - a[n][m].first - a[n][m].second);
  return 0;
}
Problem p03471 (C++)

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

using namespace std;

int main(void) {
  int n, y;
  scanf("%d %d", &n, &y);
  for (int i = 0, ii = 0; ii <= y; ++i, ii += 1000) {
    for (int j = 0, jj = 0; jj + ii <= y; ++j, jj += 5000) {
      for (int k = 0, kk = 0; ii + jj + kk <= y; ++k, kk += 10000) {
        if (ii + jj + kk == y && i + j + k == n) {
          printf("%d %d %d\n", k, j, i);
          return 0;
        }
      }
    }
  }
  puts("-1 -1 -1");
}


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

using namespace std;

int main(void) {
  int n, y;
  scanf("%d %d", &n, &y);
  for (int i = 0, ii = 0; ii <= y; ++i, ii += 1000) {
    for (int j = 0, jj = 0; jj + ii <= y; ++j, jj += 5000) {
      int k = n - i - j;
      int kk = k * 10000;
      if (ii + jj + kk == y && i + j + k == n) {
        printf("%d %d %d\n", k, j, i);
        return 0;
      }
    }
  }
  puts("-1 -1 -1");
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int n, y, ans, ic, uc, hc;
int main() {
  cin >> n >> y;

  for (int i = 0; i < n + 1; i++) {
    if (1000 * i > y || i > n)
      break;
    for (int u = 0; u < n + 1; u++) {
      if (1000 * i + 5000 * u > y || i + u > n)
        break;
      for (int h = 0; h < n + 1; h++) {
        if (1000 * i + 5000 * u + 10000 * h > y || i + u + h > n)
          break;
        if (1000 * i + 5000 * u + 10000 * h == y && i + u + h == n) {
          ic = h;
          uc = u;
          hc = i;
          ans = 1;
          break;
        }
      }
      if (ans)
        break;
    }
    if (ans)
      break;
  }

  for (int i = 0; i < 10000000000; i++) {
    int aho;
    aho++;
    for (int i = 0; i < 10; i++) {
      int ghj;
    }
  }

  if (ans == 1) {
    cout << ic << " " << uc << " " << hc << endl;
  } else {
    cout << "-1 -1 -1" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, y, ans, ic, uc, hc;
int main() {
  cin >> n >> y;

  for (int i = 0; i < n + 1; i++) {
    if (1000 * i > y || i > n)
      break;
    for (int u = 0; u < n + 1; u++) {
      if (1000 * i + 5000 * u > y || i + u > n)
        break;
      for (int h = 0; h < n + 1; h++) {
        if (1000 * i + 5000 * u + 10000 * h > y || i + u + h > n)
          break;
        if (1000 * i + 5000 * u + 10000 * h == y && i + u + h == n) {
          ic = h;
          uc = u;
          hc = i;
          ans = 1;
          break;
        }
      }
      if (ans)
        break;
    }
    if (ans)
      break;
  }

  for (int i = 0; i < 1000000000; i++) {
    int aho;
    aho++;
    for (int i = 0; i < 10; i++) {
      int ghj;
    }
  }

  if (ans == 1) {
    cout << ic << " " << uc << " " << hc << endl;
  } else {
    cout << "-1 -1 -1" << endl;
  }
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int n, y, ans, ic, uc, hc;
int main() {
  cin >> n >> y;

  for (int i = 0; i < n + 1; i++) {
    if (1000 * i > y || i > n)
      break;
    for (int u = 0; u < n + 1; u++) {
      if (1000 * i + 5000 * u > y || i + u > n)
        break;
      for (int h = 0; h < n + 1; h++) {
        if (1000 * i + 5000 * u + 10000 * h > y || i + u + h > n)
          break;
        if (1000 * i + 5000 * u + 10000 * h == y && i + u + h == n) {
          ic = h;
          uc = u;
          hc = i;
          ans = 1;
          break;
        }
      }
      if (ans)
        break;
    }
    if (ans)
      break;
  }

  for (int i = 0; i < 10000000000; i++) {
    int aho;
  }

  if (ans == 1) {
    cout << ic << " " << uc << " " << hc << endl;
  } else {
    cout << "-1 -1 -1" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, y, ans, ic, uc, hc;
int main() {
  cin >> n >> y;

  for (int i = 0; i < n + 1; i++) {
    if (1000 * i > y || i > n)
      break;
    for (int u = 0; u < n + 1; u++) {
      if (1000 * i + 5000 * u > y || i + u > n)
        break;
      for (int h = 0; h < n + 1; h++) {
        if (1000 * i + 5000 * u + 10000 * h > y || i + u + h > n)
          break;
        if (1000 * i + 5000 * u + 10000 * h == y && i + u + h == n) {
          ic = h;
          uc = u;
          hc = i;
          ans = 1;
          break;
        }
      }
      if (ans)
        break;
    }
    if (ans)
      break;
  }

  for (int i = 0; i < 1000000000 * 6; i++) {
    int aho;
  }

  if (ans == 1) {
    cout << ic << " " << uc << " " << hc << endl;
  } else {
    cout << "-1 -1 -1" << endl;
  }
}
Problem p03471 (C++)

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

#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);

#define MAXX 500005
#define INF INT_MAX

#define PI 3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll long long

#define mod 1000000007

int main() {
  FAST;
  int n, m;
  cin >> n >> m;

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

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

#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);

#define MAXX 500005
#define INF INT_MAX

#define PI 3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll long long

#define mod 1000000007

int main() {
  FAST;
  int n, m;
  cin >> n >> m;

  for (int i = 0; i <= m / 10000; i++) {
    for (int j = 0; j <= (m - i * 10000) / 5000; j++) {
      int k = m - i * 10000 - j * 5000;
      k /= 1000;
      if (i + j + k == n && (i * 10000 + j * 5000 + k * 1000) == m) {
        cout << i << " " << j << " " << k;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
typedef unsigned long long Int;
int main() {
  Int n, x;
  cin >> n >> x;
  if (x % 1000 != 0) {
    cout << "-1 -1 -1";
    return 0;
  }
  x /= 1000;

  for (Int i = 0; i <= n; i++) {
    for (Int j = 0; j <= n; j++) {
      if (i + j > n)
        continue;
      for (Int k = 0; k <= n; k++) {
        if (i + j + k != n)
          continue;
        if (10 * i + 5 * j + k == x) {
          cout << i << " " << j << " " << k;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1";
}

Fixed submission:
#include <iostream>
using namespace std;
typedef unsigned long long Int;
int main() {
  Int n, x;
  cin >> n >> x;
  if (x % 1000 != 0) {
    cout << "-1 -1 -1";
    return 0;
  }
  x /= 1000;

  for (Int i = 0; i <= n; i++) {
    for (Int j = 0; j + i <= n; j++) {
      Int k = n - i - j;
      if (10 * i + 5 * j + k == x) {
        cout << i << " " << j << " " << k;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1";
}
Problem p03471 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

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

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

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

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

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

  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= (N - x); y++) {
      int z = N - (x + y);
      if (x * 10000 + y * 5000 + z * 1000 == 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 <bits/stdc++.h>
using namespace std;

int main() {
  int N, Y, total;
  int sen = -1, gosen = -1, man = -1;
  bool judge = 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++) {
        total = i * 1000 + j * 5000 + k * 10000;
        if (total == Y && N == i + j + k) {
          judge = true;
          sen = i;
          gosen = j;
          man = k;
        }
        if (judge)
          break;
      }
      if (judge)
        break;
    }
    if (judge)
      break;
  }
  cout << man << " " << gosen << " " << sen << endl;
}

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

int main() {
  int N, Y, total;
  int sen = -1, gosen = -1, man = -1;
  bool judge = false;
  cin >> N >> Y;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; i + j <= N; j++) {
      total = i * 1000 + j * 5000 + (N - i - j) * 10000;
      if (total == Y) {
        judge = true;
        sen = i;
        gosen = j;
        man = N - i - j;
      }
      if (judge)
        break;
    }
    if (judge)
      break;
  }
  cout << man << " " << gosen << " " << sen << endl;
}
Problem p03471 (C++)

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

using namespace std;

int main() {
  int n;
  int m;

  cin >> n >> m;

  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 * 10000 + j * 5000 + k * 1000 == m) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }

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

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n;
  int m;

  cin >> n >> m;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; i + j <= n; j++) {
      int k = n - (i + j);
      if (i + j + k == n && i * 10000 + j * 5000 + k * 1000 == m) {
        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>
#define lint long long int
#define mm 1000000007
using namespace std;

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

Fixed submission:
#include <bits/stdc++.h>
#define lint long long int
#define mm 1000000007
using namespace std;

int main() {
  lint n, t;
  cin >> n >> t;
  t /= 1000;
  int x, y, z;
  for (x = 0; x <= n; x++) {
    for (y = 0; y <= n; y++) {
      z = n - x - y;
      if (10 * x + 5 * y + z == t && z >= 0) {
        cout << x << " " << y << " " << z << 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() {
  ios_base::sync_with_stdio(0);
  int n, y;
  cin >> n >> y;
  int ans = 0;
  y = y / 1000;
  for (int i = 0; i <= (y / 10); i++) {
    for (int j = 0; j <= (y / 5); j++) {
      for (int k = 0; k <= (y / 1); k++) {
        if (y == 10 * i + 5 * j + k && 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 main() {
  ios_base::sync_with_stdio(0);
  int n, y;
  cin >> n >> y;
  int ans = 0;
  y = y / 1000;
  for (int i = 0; i <= 2000; i++) {
    if (i * 10 > y || i > n)
      break;
    for (int j = 0; j <= 2000; j++) {
      if (i * 10 + j * 5 > y || i + j > n)
        break;
      for (int k = 0; k <= 2000; k++) {
        if (i * 10 + 5 * j + k > y || i + j + k > n)
          break;
        if (y == 10 * i + 5 * j + k && 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 <iostream>
#include <vector>
using namespace std;
long long int N, Y;
int main() {
  cin >> N >> Y;
  for (long long int x = 0; x <= N; x++) {
    for (long long y = 0; y <= N; y++) {
      for (long long z = 0; z <= N; z++) {
        if (x + y + z != N)
          continue;
        if (1000 * x + 5000 * y + 10000 * z == Y) {
          printf("%d %d %d\n", z, y, x);
          return 0;
        }
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
long long int N, Y;
int main() {
  cin >> N >> Y;
  for (long long int x = 0; x <= N; x++) {
    for (long long y = 0; x + y <= N; y++) {
      if (1000 * x + 5000 * y + 10000 * (N - x - y) == Y) {
        printf("%d %d %d\n", (N - x - y), y, x);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}
Problem p03471 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, a, b, c, y;
  cin >> n >> y;
  y /= 1000;
  bool flag = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if (i * 10 + j * 5 + k == y && i + j + k == n) {
          a = i;
          b = j;
          c = k;
          flag = 1;
          break;
        }
      }
      if (flag)
        break;
    }
    if (flag)
      break;
  }
  if (flag)
    printf("%d %d %d\n", a, b, c);
  else
    printf("-1 -1 -1\n");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, a, b, c, y;
  cin >> n >> y;
  y /= 1000;
  bool flag = 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++) {
        if (i * 10 + j * 5 + k == y && i + j + k == n) {
          a = i;
          b = j;
          c = k;
          flag = 1;
          break;
        }
      }
      if (flag)
        break;
    }
    if (flag)
      break;
  }
  if (flag)
    printf("%d %d %d\n", a, b, c);
  else
    printf("-1 -1 -1\n");
  return 0;
}
Problem p03471 (C++)

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

int main() {
  int n;
  cin >> n;
  int y;
  cin >> y;
  int cnt = 0;
  bool found = false;
  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;
            found = true;
            break;
          }
        }
      }
      if (found == true) {
        break;
      }
    }
    if (found == true) {
      break;
    }
  }
  if (found == false) {
    cout << -1 << " " << -1 << " " << -1;
  }
}


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

int main() {
  int n;
  cin >> n;
  int y;
  cin >> y;
  int cnt = 0;
  bool found = false;
  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) {
          if (10000 * i + 5000 * j + 1000 * k == y) {
            cout << i << " " << j << " " << k;
            found = true;
            break;
          }
        }
      }
      if (found == true) {
        break;
      }
    }
    if (found == true) {
      break;
    }
  }
  if (found == false) {
    cout << -1 << " " << -1 << " " << -1;
  }
}
Problem p03471 (C++)

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

using namespace std;

int main() {
  int m, n;
  scanf("%d%d", &m, &n);

  if (m * 10000 < n) {
    printf("-1 -1 -1");
    return 0;
  }
  if (m * 1000 > n) {
    printf("-1 -1 -1");
    return 0;
  }
  if (n % 1000 != 0) {
    printf("-1 -1 -1");
    return 0;
  }
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0;
           k <= m, i + j + k <= m, i * 1000 + j * 5000 + k * 10000 <= n; k++) {
        if (i + j + k == m && i * 1000 + j * 5000 + k * 10000 == n) {
          printf("%d %d %d", k, j, i);
          return 0;
        }
      }
  printf("-1 -1 -1");
  return 0;
}

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

using namespace std;

int main() {
  int m, n;
  scanf("%d%d", &m, &n);

  if (m * 10000 < n) {
    printf("-1 -1 -1");
    return 0;
  }
  if (m * 1000 > n) {
    printf("-1 -1 -1");
    return 0;
  }
  if (n % 1000 != 0) {
    printf("-1 -1 -1");
    return 0;
  }
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= m, i + j + k <= m; k++) {
        if (i + j + k == m && i * 1000 + j * 5000 + k * 10000 == n) {
          printf("%d %d %d", k, j, i);
          return 0;
        }
      }
  printf("-1 -1 -1");
  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 a = 0; a <= N; a++) {
    for (int b = 0; b <= N; b++) {
      for (int c = 0; c <= N; c++) {
        if (a + b + c == N && 10000 * a + 5000 * b + 1000 * c == Y) {
          cout << a << " " << b << " " << c << 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 a = 0; a <= N; a++) {
    for (int b = 0; b <= N; b++) {
      if (N - a - b >= 0 && 10000 * a + 5000 * b + 1000 * (N - a - b) == Y) {
        cout << a << " " << b << " " << N - a - b << 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 fol(i, n) for (int i = 0; i < n; i++)
const int lim = 2001;
const int a = 10000, b = 5000, c = 1000;
int ans[3] = {-1, -1, -1};

void cyl(int n, int y) {
  fol(i, lim) {
    fol(j, lim) {
      fol(k, lim) {
        if ((i + j + k == n) && a * i + b * j + c * k == y) {
          ans[0] = i, ans[1] = j, ans[2] = k;
          return;
        }
      }
    }
  }
}
int main() {
  int n, y;
  cin >> n >> y;
  cyl(n, y);
  printf("%d %d %d\n", ans[0], ans[1], ans[2]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fol(i, n) for (int i = 0; i < n; i++)
const int lim = 2001;
const int a = 10000, b = 5000, c = 1000;
int ans[3] = {-1, -1, -1};

void cyl(int n, int y) {
  fol(i, n + 1) {
    fol(j, n + 1 - i) {
      fol(k, n + 1 - i - j) {
        if ((i + j + k == n) && a * i + b * j + c * k == y) {
          ans[0] = i, ans[1] = j, ans[2] = k;
          return;
        }
      }
    }
  }
}
int main() {
  int n, y;
  cin >> n >> y;
  cyl(n, y);
  printf("%d %d %d\n", ans[0], ans[1], ans[2]);
  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 k = 0; k <= N; k++) {
        if (i + j + k != N)
          continue;
        if (10000 * k + 5000 * j + 1000 * i == Y) {
          cout << k << " " << j << " " << i << 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 i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      int k = N - i - j;
      if (k >= 0 && 10000 * k + 5000 * j + 1000 * i == 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 <bits/stdc++.h>
using namespace std;

int main() {
  int n, Y;
  cin >> n >> Y;
  bool ok = false;
  for (int x = 0; x <= 2000; x++) {
    for (int y = 0; y <= 2000; y++) {
      for (int z = 0; z <= 2000; z++) {
        if (10000 * x + 5000 * y + 1000 * z == Y && x + y + z == n) {
          ok = true;
          cout << x << ' ' << y << ' ' << z << endl;
          break;
        }
      }
      if (ok) {
        break;
      }
    }
    if (ok) {
      break;
    }
  }
  if (!ok) {
    cout << "-1 -1 -1" << endl;
  }
}

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

int main() {
  int n, Y;
  cin >> n >> Y;
  bool ok = false;
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      if (10000 * x + 5000 * y + 1000 * (n - x - y) == Y && n - x - y >= 0) {
        ok = true;
        cout << x << ' ' << y << ' ' << n - x - y << endl;
        break;
      }
    }
    if (ok) {
      break;
    }
  }
  if (!ok) {
    cout << "-1 -1 -1" << endl;
  }
}
Problem p03471 (C++)

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

int main() {
  int n, y;
  scanf("%d%d", &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) {
          printf("%d %d %d", i, j, k);
          return 0;
        }
  printf("-1 -1 -1");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

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

  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      if (y == i * 10000 + j * 5000 + (n - i - j) * 1000 && n - i - j >= 0) {
        printf("%d %d %d", i, j, n - i - j);
        return 0;
      }
  printf("-1 -1 -1");
  return 0;
}
Problem p03471 (C++)

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

using namespace std;

int main(void) {

  int n, yen, x, y, z, mai, sum, kx, ky, kz;
  bool endswc;

  x = 10000;
  y = 5000;
  z = 1000;
  endswc = false;

  cin >> n >> yen;

  for (kx = 0; kx <= n; kx++) {
    if (endswc == true)
      break;
    for (ky = 0; ky <= n; ky++) {
      if (endswc == true)
        break;
      for (kz = 0; kz <= n; kz++) {
        mai = kx + ky + kz;
        sum = x * kx + y * ky + z * kz;
        if (mai == n && sum == yen) {
          printf("%d %d %d\n", kx, ky, kz);
          endswc = true;
          break;
        } else if (kx == n && ky == n && kz == n) {
          printf("-1 -1 -1\n");
        }
      }
    }
  }

  return 0;
}


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

using namespace std;

int main(void) {

  int n, yen, x, y, z, mai, sum, kx, ky, kz;
  bool endswc;

  x = 10000;
  y = 5000;
  z = 1000;
  endswc = false;

  cin >> n >> yen;

  for (kx = 0; kx <= n; kx++) {
    if (endswc == true)
      break;
    for (ky = 0; ky <= n; ky++) {
      if (endswc == true)
        break;
      kz = n - kx - ky;
      sum = x * kx + y * ky + z * kz;
      if (kz >= 0 && sum == yen) {
        printf("%d %d %d\n", kx, ky, kz);
        endswc = true;
        break;
      } else if (kx == n && ky == n) {
        printf("-1 -1 -1\n");
      }
    }
  }

  return 0;
}
Problem p03471 (C++)

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

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

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

int n, y;

int main() {
  int i, j, k;

  cin >> n >> y;

  for (i = 0; i <= 2000; i++)
    for (j = 0; j <= 2000; j++)
      for (k = 0; k <= 2000; 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 <iostream>
using namespace std;

int n, y;

int main() {
  int i, j, k;

  cin >> n >> y;

  for (i = 0; i <= 2000; i++)
    for (j = 0; j <= 2000 - i; j++)
      for (k = 0; k <= 2000 - i - j; 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;
}