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

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

int main() {
  long long int n;
  cin >> n;
  vector<long long int> t(5);
  for (long long int i = 0; i < 5; i++) {
    cin >> t[i];
  }
  vector<long long int> p(6, 0);
  p[0] = n;
  long long int ans = 0;
  while (p[5] < n) {
    for (long long int i = 5; i > 0; i--) {
      p[i] += min(t[i - 1], p[i - 1]);
      p[i - 1] -= min(t[i - 1], p[i - 1]);
    }
    ans++;
  }
  cout << ans << endl;
}

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

int main() {
  long long int n;
  cin >> n;
  vector<long long int> t(5);
  for (long long int i = 0; i < 5; i++) {
    cin >> t[i];
  }
  sort(t.begin(), t.end());
  cout << (n + t[0] - 1) / t[0] + 4 << endl;
}
Problem p03077 (C++)

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

int MinIndex(const unsigned long long int *const array, const int size);

int main() {
  unsigned long long int N;
  unsigned long long int board[5];

  cin >> N;

  for (int i = 0; i < 5; i++)
    cin >> board[i];

  int bottleNeckIndex = MinIndex(board, sizeof(board));

  unsigned long long int ans =
      (unsigned long long int)(N / board[bottleNeckIndex]) + 4;

  if ((N % board[bottleNeckIndex]) != 0)
    ans++;

  cout << ans;

  return 0;
}

int MinIndex(const unsigned long long int *const array, const int size) {
  int minIndex = 0;
  unsigned long long int minValue = array[0];

  for (int i = 1; i < size; i++) {
    if (array[i] < minValue) {
      minIndex = i;
      minValue = array[i];
    }
  }

  return minIndex;
}

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

int MinIndex(const unsigned long long int *const array, const int size);

int main() {
  unsigned long long int N;
  unsigned long long int board[5];

  cin >> N;

  for (int i = 0; i < 5; i++)
    cin >> board[i];

  int bottleNeckIndex = MinIndex(board, 5);

  unsigned long long int ans =
      (unsigned long long int)(N / board[bottleNeckIndex]) + 4;

  if ((N % board[bottleNeckIndex]) != 0)
    ans++;

  cout << ans;

  return 0;
}

int MinIndex(const unsigned long long int *const array, const int size) {
  int minIndex = 0;
  unsigned long long int minValue = array[0];

  for (int i = 1; i < size; i++) {
    if (array[i] < minValue) {
      minIndex = i;
      minValue = array[i];
    }
  }

  return minIndex;
}
Problem p03077 (C++)

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

#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))

int main(void) {
  int a[5];
  long long n, fa[10], fd[10], la[10], ld[10];

  cin >> n;
  fa[0] = la[0] = 0;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
    fd[i] = fa[i];
    ld[i] = MAX(la[i], fa[i] + (n - 1) / a[i]);
    //    cout << fd[i] << " " << ld[i] << endl;
    fa[i + 1] = fd[i] + 1;
    la[i + 1] = ld[i] + 1;
  }
  cout << la[5] << endl;
  return 0;
}


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

#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))

int main(void) {
  long long a[5];
  long long n, fa[10], fd[10], la[10], ld[10];

  cin >> n;
  fa[0] = la[0] = 0;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
    fd[i] = fa[i];
    ld[i] = MAX(la[i], fa[i] + (n - 1) / a[i]);
    //    cout << fd[i] << " " << ld[i] << endl;
    fa[i + 1] = fd[i] + 1;
    la[i + 1] = ld[i] + 1;
  }
  cout << la[5] << endl;
  return 0;
}
Problem p03077 (C++)

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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(obj) (v.begin(obj), v.end(obj))
#define COUT(x) cout << (x) << endl;

int main() {
  ll n, a, b, c, d, e;
  cin >> n;
  ll min1 = min({a, b, c, d, e});
  COUT((n + min1 - 1) / min1 + 4)
  return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(obj) (v.begin(obj), v.end(obj))
#define COUT(x) cout << (x) << endl;

int main() {
  ll n, a, b, c, d, e;
  cin >> n;
  cin >> a >> b >> c >> d >> e;
  ll min1 = min({a, b, c, d, e});
  COUT((n + min1 - 1) / min1 + 4)
  return 0;
}
Problem p03077 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main() {
  ll N;
  cin >> N;
  vector<int> a(5);
  for (int i = 0; i < 5; i++)
    cin >> a[i];

  sort(a.begin(), a.end());
  ll minv = a[0];
  ll turn;
  if (a[0] == 1)
    turn = N;
  else
    turn = (N - 1) / minv + 1;

  cout << turn + 4 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main() {
  ll N;
  cin >> N;
  vector<ll> a(5);
  for (int i = 0; i < 5; i++)
    cin >> a[i];

  sort(a.begin(), a.end());
  ll minv = a[0];
  ll turn;
  if (a[0] == 1)
    turn = N;
  else
    turn = (N - 1) / minv + 1;

  cout << turn + 4 << endl;
}
Problem p03077 (C++)

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

const ll INF = pow(10, 18) + 1;

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

template <typename T> bool chmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <typename T> bool chmax(T &a, T b) {
  return a < b ? a = b, true : false;
}

int main() {
  ll N, A[10];
  cin >> N;
  ll mn = INF;
  int mn_place = 0;
  REP(i, 5) {
    cin >> A[i];
    if (A[i] < mn) {
      mn = A[i];
      mn_place = i;
    }
  }
  ll B[6] = {N, 0, 0, 0, 0, 0};
  ll res = 0;
  /*if(mn < N){
      if(mn_place!=0) res = (N / mn) + 1 + (5-mn_place);
      else res = (N / mn) + 5;
  } else {
      res = 5;
  }*/
  while (B[5] != N) {
    if (B[4] != 0) {
      if (B[4] > A[4]) {
        B[5] += A[4];
        B[4] -= A[4];
      } else {
        B[5] += B[4];
        B[4] -= B[4];
      }
    }
    if (B[3] != 0) {
      if (B[3] > A[3]) {
        B[4] += A[3];
        B[3] -= A[3];
      } else {
        B[4] += B[3];
        B[3] -= B[3];
      }
    }
    if (B[2] != 0) {
      if (B[2] > A[2]) {
        B[3] += A[2];
        B[2] -= A[2];
      } else {
        B[3] += B[2];
        B[2] -= B[2];
      }
    }
    if (B[1] != 0) {
      if (B[1] > A[1]) {
        B[2] += A[1];
        B[1] -= A[1];
      } else {
        B[2] += B[1];
        B[1] -= B[1];
      }
    }
    if (B[0] != 0) {
      if (B[0] > A[0]) {
        B[1] += A[0];
        B[0] -= A[0];
      } else {
        B[1] += B[0];
        B[0] -= B[0];
      }
    }
    res++;
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
using ll = long long;

const ll INF = pow(10, 18) + 1;

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

template <typename T> bool chmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <typename T> bool chmax(T &a, T b) {
  return a < b ? a = b, true : false;
}

int main() {
  ll N, A[10];
  cin >> N;
  REP(i, 5) { cin >> A[i]; }
  ll mn = min(A[0], min(A[1], min(A[2], min(A[3], A[4]))));
  ll res = ceil((N - 1) / mn) + 5;
  cout << res << endl;
  return 0;
}
Problem p03077 (C++)

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

int main() {
  int N, A, B, C, D, E;
  cin >> N, A, B, C, D, E;
  int MIN = min({A, B, C, D, E});
  cout << 5 + (N - 1) / MIN << endl;

  return 0;
}


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

int main() {
  long N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  long MIN = min({A, B, C, D, E});
  cout << 5 + (N - 1) / MIN << endl;

  return 0;
}
Problem p03077 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#define INF 100000000
using namespace std;
int main(void) {
  long N;
  long trans1[5], trans2[5];
  cin >> N;
  for (int i = 0; i < 5; i++) {
    cin >> trans1[i];
    if (N % trans1[i] != 0) {
      trans2[i] = N / trans1[i] + 1;
    } else
      trans2[i] = N / trans1[i];
  }
  sort(trans2, trans2 + N);
  cout << trans2[0] + 4;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#define INF 100000000
using namespace std;
int main(void) {
  long N;
  long trans1[5], trans2[5];
  cin >> N;
  for (int i = 0; i < 5; i++) {
    cin >> trans1[i];
    if (N % trans1[i] != 0) {
      trans2[i] = N / trans1[i] + 1;
    } else
      trans2[i] = N / trans1[i];
  }
  sort(trans2, trans2 + 5);
  cout << trans2[4] + 4;
  return 0;
}
Problem p03077 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  vector<int> a(5);
  cin >> n;
  rep(i, 5) cin >> a[i];
  ll minmove = *std::min_element(a.begin(), a.end());
  ll ans = ((n + minmove - 1) / minmove) + 4;
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  vector<ll> a(5);
  cin >> n;
  rep(i, 5) cin >> a[i];
  ll minmove = *std::min_element(a.begin(), a.end());
  ll ans = ((n + minmove - 1) / minmove) + 4;
  cout << ans << endl;

  return 0;
}
Problem p03077 (C++)

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

long long int min(long long int a, long long int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}

long long int fivemin(long long int a, long long int b, long long int c,
                      long long int d, long long int e) {
  return min(min(min(a, b), min(c, d)), e);
}

int main() {
  long long int N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;

  long long int output = 0;
  // output = 5;
  // output += N / fivemin(A, B, C, D, E);

  long long int city1 = N;
  long long int city2 = 0;
  long long int city3 = 0;
  long long int city4 = 0;
  long long int city5 = 0;
  long long int city6 = 0;

  while (1) {
    if (city6 == N) {
      break;
    }

    if (city5 >= E) {
      city5 -= E;
      city6 += E;
    } else if (city5 > 0) {
      city6 += city5;
      city5 = 0;
    }
    if (city4 >= D) {
      city4 -= D;
      city5 += D;
    } else if (city4 > 0) {
      city5 += city4;
      city4 = 0;
    }
    if (city3 >= C) {
      city3 -= C;
      city4 += C;
    } else if (city3 > 0) {
      city4 += city3;
      city3 = 0;
    }
    if (city2 >= B) {
      city2 -= B;
      city3 += B;
    } else if (city2 > 0) {
      city3 += city2;
      city2 = 0;
    }
    if (city1 >= A) {
      city1 -= A;
      city2 += A;
    } else if (city1 > 0) {
      city2 += city1;
      city1 = 0;
    }

    output++;
  }

  cout << output << endl;

  return 0;
}


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

long long int min(long long int a, long long int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}

long long int fivemin(long long int a, long long int b, long long int c,
                      long long int d, long long int e) {
  return min(min(min(a, b), min(c, d)), e);
}

int main() {
  long long int N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;

  long long int output = 0;
  // output = 5;
  // output += N / fivemin(A, B, C, D, E);
  output = 4;
  output += N / fivemin(A, B, C, D, E);
  if (N % fivemin(A, B, C, D, E) != 0) {
    output++;
  }

  cout << output << endl;

  return 0;
}
Problem p03077 (C++)

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

int main() {
  int n, a[5];
  cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  sort(a, a + 5);
  cout << (n - 1) / a[0] + 5 << endl;
}


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

int main() {
  long long n, a[5];
  cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  sort(a, a + 5);
  cout << (n - 1) / a[0] + 5 << endl;
}
Problem p03077 (C++)

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

int main() {
  long long int n;
  cin >> n;
  int a[5]; // cout<<"unko"<<endl;
  for (int i = 0; i < 5; i++) {
    cin >> a[i]; // cout<<a[i]<<endl;
  }
  sort(a, a + 5);

  if (n % a[0] != 0)
    cout << n / a[0] + 5 << endl;
  else
    cout << n / a[0] + 4 << endl;
}


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

int main() {
  long long int n;
  cin >> n;
  long long int a[5]; // cout<<"unko"<<endl;
  for (int i = 0; i < 5; i++) {
    cin >> a[i]; // cout<<a[i]<<endl;
  }
  sort(a, a + 5);

  if (n % a[0] != 0)
    cout << n / a[0] + 5 << endl;
  else
    cout << n / a[0] + 4 << endl;
}
Problem p03077 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d;
  cout << (n / min({a, b, c, d, e})) + 4 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  cout << (n + min({a, b, c, d, e}) - 1) / min({a, b, c, d, e}) + 4 << endl;
}
Problem p03077 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll a, b, c, d, e;
  cin >> a, b, c, d, e;
  ll m = min(a, min(b, min(c, min(d, e))));
  ll ans = 4 + (n + m - 1) / m;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  ll m = min(a, min(b, min(c, min(d, e))));
  ll ans = 4 + (n + m - 1) / m;
  cout << ans << endl;
  return 0;
}
Problem p03077 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

typedef long long ll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
int guki(int a) {
  if (a % 2 == 0)
    return 0;
  else
    return 1;
}
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) {
  int x = gcd(a, b);
  return (a * b / x);
}
using namespace std;
int main() {
  ll n, ans = 0;
  cin >> n;

  vector<pair<ll, ll>> vec(6);
  REP(i, 5) {
    ll a;
    cin >> a;
    vec[i].first = a;
    vec[i].second = 0;
  }

  vec[0].second = n;
  vec[5].second = 0;
  while (vec[5].second != n) {
    for (int i = 5; 0 < i; i--) {
      if (vec[i - 1].second == 0) {
        continue;
      } else if (vec[i - 1].second >= vec[i - 1].first) {
        vec[i].second += vec[i - 1].first;
        vec[i - 1].second -= vec[i - 1].first;
      } else {
        vec[i].second += vec[i - 1].second;
        vec[i - 1].second = 0;
      }
    }
    ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

typedef long long ll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
int guki(int a) {
  if (a % 2 == 0)
    return 0;
  else
    return 1;
}
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) {
  int x = gcd(a, b);
  return (a * b / x);
}
using namespace std;
int main() {
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  cout << max({(n - 1) / a, (n - 1) / b, (n - 1) / c, (n - 1) / d,
               (n - 1) / e}) +
              5
       << endl;
}
Problem p03077 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

int main() {
  ll N;
  std::cin >> N;

  std::vector<int> capacities(5);

  auto min = 10000000000000000;
  for (auto i = 0; i < 5; ++i) {
    std::cin >> capacities[i];
    if (capacities[i] < min)
      min = capacities[i];
  }

  ll result = N / min + 4;
  auto mod = N % min;
  if (mod != 0)
    result++;

  std::cout << result << std::endl;
}

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

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

int main() {
  ll N;
  std::cin >> N;

  std::vector<ll> capacities(5);
  auto min = 10000000000000000;
  for (auto i = 0; i < 5; ++i) {
    std::cin >> capacities[i];
    if (capacities[i] < min)
      min = capacities[i];
  }

  ll result = N / min + 4;
  auto mod = N % min;
  if (mod != 0)
    result++;

  std::cout << result << std::endl;
}
Problem p03077 (C++)

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint, vector<llint>, greater<llint>> que;
priority_queue<llint> Que;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve() {
  llint n;
  vector<llint> a(5);
  cin >> n;
  llint mn = inf;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
    mn = min(a[i], mn);
  }
  llint ans = 5;
  n -= mn;
  while (n > 0) {
    ans += 1;
    n -= mn;
  }
  cout << ans << endl;
}

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


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint, vector<llint>, greater<llint>> que;
priority_queue<llint> Que;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve() {
  llint n;
  vector<llint> a(5);
  cin >> n;
  llint mn = inf;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
    mn = min(a[i], mn);
  }
  llint ans = 0;
  if (n % mn == 0) {
    ans += 5 + n / mn;
  } else
    ans += 6 + n / mn;

  cout << ans - 1 << endl;
}

int main() {
  solve();
  return 0;
}
Problem p03077 (C++)

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

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

int main() {
  ll n;
  cin >> n;
  vector<int> a(5);
  rep(i, 5) cin >> a[i];

  ll mina = *min_element(ALL(a));
  cout << ((n + mina - 1) / mina) + 4 << endl;
}

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

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(5);
  rep(i, 5) cin >> a[i];

  ll mina = *min_element(ALL(a));
  cout << ((n + mina - 1) / mina) + 4 << endl;
}
Problem p03077 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T> T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }

int main() {
  ll n;
  cin >> n;
  vector<ll> v(5);
  int r;
  ll m = INF;
  rep(i, 5) {
    cin >> v[i];
    if (chmin(m, v[i]))
      r = i;
  }
  ll ans = 4;
  if (n % v[r])
    ans += n / v[r] + 1;
  else
    ans += n / v[r];
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e18
#define PIE 3.14159265358979323

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;
}
template <class T> T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }

int main() {
  ll n;
  cin >> n;
  vector<ll> v(5);
  int r;
  ll m = INF;
  rep(i, 5) {
    cin >> v[i];
    if (chmin(m, v[i]))
      r = i;
  }
  ll ans = 4;
  if (n % v[r])
    ans += n / v[r] + 1;
  else
    ans += n / v[r];
  cout << ans << endl;
  return 0;
}
Problem p03077 (C++)

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

int main() {
  int64_t n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  int64_t cntn = n, cnta = 0, cntb = 0, cntc = 0, cntd = 0, cnte = 0, ans = 0;
  while (cnte < n) {
    cnte += min(cntd, e);
    cntd -= min(cntd, e);
    cntd += min(cntc, d);
    cntc -= min(cntc, d);
    cntc += min(cntb, c);
    cntb -= min(cntb, c);
    cntb += min(cnta, b);
    cnta -= min(cnta, b);
    cnta += min(cntn, a);
    cntn -= min(cntn, a);
    ans++;
  }
  cout << ans;
}

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

int main() {
  int64_t n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  cout << (int64_t)ceil((double)n / min(a, min(b, min(c, min(d, e))))) + 4;
}
Problem p03077 (C++)

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

int main() {
  long long a[10];
  long long b[10];
  long long count = 0;
  memset(b, 0, sizeof(b));
  long long n;
  scanf("%lld", &n);
  for (int i = 0; i < 5; i++) {
    scanf("%lld", &a[i]);
  }
  b[0] = n;
  while (b[0] + b[1] + b[2] + b[3] + b[4] != 0) {
    count++;
    for (int i = 5; i > 0; i--) {
      if (b[i - 1] != 0) {
        if (b[i - 1] > a[i - 1]) {
          b[i] += a[i - 1];
          b[i - 1] -= a[i - 1];
        } else {
          b[i] += b[i - 1];
          b[i - 1] = 0;
        }
      }
    }
  }
  printf("%lld", count);
  return 0;
}

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

int main() {

  long long N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  cout << max({(N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D,
               (N - 1) / E}) +
              5
       << endl;

  return 0;
}
Problem p03077 (C++)

Buggy submission (status: Runtime Error):
/*Function Template*/
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for (long long int i = 0; i < (n); i++)

int Len(int n) {
  int s = 0;
  while (n != 0)
    s++, n /= 10;
  return s;
}

int Sint(int n) {
  int m = 0, s = 0, a = n;
  while (a != 0)
    s++, a /= 10;
  for (int i = s - 1; i >= 0; i--)
    m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
  return m;
}

int Svec(vector<int> v) {
  int n = 0;
  for (int i = 0; i < v.size(); i++)
    n += v[i];
  return n;
}

int GCD(int a, int b) {
  int r, tmp;
  /*自然数 a > b を確認・入替*/
  if (a < b) {
    tmp = a, a = b, b = tmp;
  }
  /*ユークリッドの互除法*/
  r = a % b;
  while (r != 0) {
    a = b, b = r, r = a % b;
  }
  return b;
}

int LCM(int a, int b) {
  int c = a, d = b, r, tmp;
  /*自然数 a > b を確認・入替*/
  if (a < b) {
    tmp = a, a = b, b = tmp;
  }
  /*ユークリッドの互除法*/
  r = a % b;
  while (r != 0) {
    a = b, b = r, r = a % b;
  }
  return c / b * d;
}

int Factorial(int n) {
  int m = 1;
  while (n >= 1)
    m *= n, n--;
  return m;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  cout << (n + v[0] - 1) / v[0] + 4 << endl;
}

Fixed submission:
/*Function Template*/
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for (long long int i = 0; i < (n); i++)

int Len(int n) {
  int s = 0;
  while (n != 0)
    s++, n /= 10;
  return s;
}

int Sint(int n) {
  int m = 0, s = 0, a = n;
  while (a != 0)
    s++, a /= 10;
  for (int i = s - 1; i >= 0; i--)
    m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
  return m;
}

int Svec(vector<int> v) {
  int n = 0;
  for (int i = 0; i < v.size(); i++)
    n += v[i];
  return n;
}

int GCD(int a, int b) {
  int r, tmp;
  /*自然数 a > b を確認・入替*/
  if (a < b) {
    tmp = a, a = b, b = tmp;
  }
  /*ユークリッドの互除法*/
  r = a % b;
  while (r != 0) {
    a = b, b = r, r = a % b;
  }
  return b;
}

int LCM(int a, int b) {
  int c = a, d = b, r, tmp;
  /*自然数 a > b を確認・入替*/
  if (a < b) {
    tmp = a, a = b, b = tmp;
  }
  /*ユークリッドの互除法*/
  r = a % b;
  while (r != 0) {
    a = b, b = r, r = a % b;
  }
  return c / b * d;
}

int Factorial(int n) {
  int m = 1;
  while (n >= 1)
    m *= n, n--;
  return m;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  long long int n;
  cin >> n;
  vector<long long int> v(5);
  rep(i, 5) cin >> v[i];
  sort(v.begin(), v.end());
  cout << (n + v[0] - 1) / v[0] + 4 << endl;
}
Problem p03077 (C++)

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

int main() {
  vector<long long> city(5, 0);
  int n;
  cin >> n;
  for (int i = 0; i < 5; i++)
    cin >> city[i];
  sort(city.begin(), city.end());
  long long rtn = 0;
  if (n % city[0] == 0) {
    rtn += n / city[0];
  } else {
    rtn += n / city[0] + 1;
  }
  rtn += 4;

  cout << rtn << endl;
}


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

int main() {
  vector<long long> city(5, 0);
  long long n;
  cin >> n;
  for (int i = 0; i < 5; i++)
    cin >> city[i];
  sort(city.begin(), city.end());
  long long rtn = 0;
  if (n % city[0] == 0) {
    rtn += n / city[0];
  } else {
    rtn += n / city[0] + 1;
  }
  rtn += 4;

  cout << rtn << endl;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

ll a[1001], b[1001], c[1001];
int x, y, z, k;
ll st1[1000001], st2[1000001];
int main() {
  cin >> x >> y >> z >> k;
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  rep(i, x) rep(j, y) st1[i * y + j] = a[i] + b[j];
  sort(st1, st1 + x * y, greater<ll>());
  int p = min(k, x * y);
  rep(i, p) rep(j, z) { st2[i * z + j] = st1[i] + c[j]; }
  sort(st2, st2 + p * z, greater<ll>());
  rep(i, k) { cout << st2[i] << endl; }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

ll a[1001], b[1001], c[1001];
int x, y, z, k;
ll st1[3000001], st2[3000001];
int main() {
  cin >> x >> y >> z >> k;
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  rep(i, x) rep(j, y) st1[i * y + j] = a[i] + b[j];
  sort(st1, st1 + x * y, greater<ll>());
  int p = min(k, x * y);
  rep(i, p) rep(j, z) { st2[i * z + j] = st1[i] + c[j]; }
  sort(st2, st2 + p * z, greater<ll>());
  rep(i, k) { cout << st2[i] << endl; }
  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)

int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;

// --------------------------------------
int x, y, z, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> x >> y >> z >> k;

  vector<ll> a(x);
  vector<ll> b(y);
  vector<ll> c(z);

  REP(i, x) cin >> a[i];
  REP(i, y) cin >> b[i];
  REP(i, z) cin >> c[i];

  vector<ll> ab(x + y);

  REP(i, x) {
    REP(j, y) { ab.push_back(a[i] + b[j]); }
  }

  sort(ab.begin(), ab.end(), greater<ll>());

  vector<ll> abc((x + y) * z);
  REP(i, ab.size()) {
    REP(j, z) { abc.push_back(ab[i] + c[j]); }
  }

  sort(abc.begin(), abc.end(), greater<ll>());
  REP(i, k) { cout << abc[i] << endl; }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)

int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;

// --------------------------------------
int x, y, z, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> x >> y >> z >> k;

  vector<ll> a(x);
  vector<ll> b(y);
  vector<ll> c(z);

  REP(i, x) cin >> a[i];
  REP(i, y) cin >> b[i];
  REP(i, z) cin >> c[i];

  vector<ll> ab(x + y);

  REP(i, x) {
    REP(j, y) { ab.push_back(a[i] + b[j]); }
  }

  sort(ab.begin(), ab.end(), greater<ll>());

  vector<ll> abc((x + y) * z);
  REP(i, min((int)ab.size(), k)) {
    REP(j, z) { abc.push_back(ab[i] + c[j]); }
  }

  sort(abc.begin(), abc.end(), greater<ll>());
  REP(i, k) { cout << abc[i] << endl; }
}
Problem p03078 (C++)

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

using namespace std;
#define LL long long
LL a[1005], b[1005], c[1005];

vector<LL> ans;

int main() {
  LL x, y, z, k;
  while (cin >> x >> y >> z >> k) {
    for (int i = 0; i < x; i++)
      cin >> a[i];
    for (int i = 0; i < y; i++)
      cin >> b[i];
    for (int i = 0; i < z; i++)
      cin >> c[i];
    sort(a, a + x, greater<LL>());
    sort(b, b + y, greater<LL>());
    sort(c, c + z, greater<LL>());
    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        for (int l = 0; l < z; l++) {
          ans.push_back(a[i] + b[j] + c[l]);
        }
      }
    }
    sort(ans.begin(), ans.end(), greater<LL>());
    for (int i = 0; i < k; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}


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

using namespace std;
#define LL long long
LL a[1005], b[1005], c[1005];

vector<LL> ans;

int main() {
  LL x, y, z, k;
  while (cin >> x >> y >> z >> k) {
    for (int i = 0; i < x; i++)
      cin >> a[i];
    for (int i = 0; i < y; i++)
      cin >> b[i];
    for (int i = 0; i < z; i++)
      cin >> c[i];
    sort(a, a + x, greater<LL>());
    sort(b, b + y, greater<LL>());
    sort(c, c + z, greater<LL>());
    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        for (int l = 0; l < z; l++) {
          if ((i + 1) * (j + 1) * (l + 1) <= k)
            ans.push_back(a[i] + b[j] + c[l]);
          else
            break;
        }
      }
    }
    sort(ans.begin(), ans.end(), greater<LL>());
    for (int i = 0; i < k; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}
Problem p03078 (C++)

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

using namespace std;

int main() {
  long long X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  long long A[X], B[Y], C[Z];

  for (int i = 0; i < X; i++)
    cin >> A[i];
  for (int i = 0; i < Y; i++)
    cin >> B[i];
  for (int i = 0; i < Z; i++)
    cin >> C[i];

  sort(A, A + X, greater<long long>());
  sort(B, B + Y, greater<long long>());
  sort(C, C + Z, greater<long long>());

  vector<long long> ans;
  for (int x = 0; x < X; x++) {
    for (int y = 0; y < Y; y++) {
      for (int z = 0; z < Z; z++) {
        ans.push_back(A[x] + B[y] + C[z]);
        // if (x * y * z > K) break;
      }
    }
  }
  sort(ans.begin(), ans.end(), greater<long long>());

  for (int i = 0; i < K; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


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

using namespace std;

int main() {
  long long X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  long long A[X], B[Y], C[Z];

  for (int i = 0; i < X; i++)
    cin >> A[i];
  for (int i = 0; i < Y; i++)
    cin >> B[i];
  for (int i = 0; i < Z; i++)
    cin >> C[i];

  sort(A, A + X, greater<long long>());
  sort(B, B + Y, greater<long long>());
  sort(C, C + Z, greater<long long>());

  vector<long long> ans;
  for (int x = 0; x < X; x++) {
    for (int y = 0; y < Y; y++) {
      for (int z = 0; z < Z; z++) {
        ans.push_back(A[x] + B[y] + C[z]);
        if (x * y * z > K)
          break;
      }
    }
  }
  sort(ans.begin(), ans.end(), greater<long long>());

  for (int i = 0; i < K; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i, m, n) for (lli i = m; i < n; i++)
#define rrep(i, m, n) for (lli i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S))
#define TV(K, L, N, M, R, S)                                                   \
  vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S)))
#define pint pair<lli, lli>
#define paf(L, R) pair<L, R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int main() {
  lli A, B, C, D, E, F, N, M, K, L, R, X, Y, H, W, sum = 0, num = 0, flag = 0;
  string S, T;
  cin >> A >> B >> C >> K;
  Vec(P, lli, A, 0);
  Vec(Q, lli, B, 0);
  Vec(O, lli, C, 0);
  rep(i, 0, A) cin >> P[i];
  rep(i, 0, B) cin >> Q[i];
  rep(i, 0, C) cin >> O[i];
  priority_queue<lli> que;
  rep(i, 0, A) rep(j, 0, B) rep(k, 0, C) {
    if ((i + 1) * (j + 1) * (k + 1) < K)
      break;
    que.push(P[i] + Q[j] + O[k]);
  }
  rep(i, 0, K) {
    Out(que.top());
    que.pop();
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i, m, n) for (lli i = m; i < n; i++)
#define rrep(i, m, n) for (lli i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S))
#define TV(K, L, N, M, R, S)                                                   \
  vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S)))
#define pint pair<lli, lli>
#define paf(L, R) pair<L, R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int main() {
  lli A, B, C, D, E, F, N, M, K, L, R, X, Y, H, W, sum = 0, num = 0, flag = 0;
  string S, T;
  cin >> A >> B >> C >> K;
  Vec(P, lli, A, 0);
  Vec(Q, lli, B, 0);
  Vec(O, lli, C, 0);
  rep(i, 0, A) cin >> P[i];
  rep(i, 0, B) cin >> Q[i];
  rep(i, 0, C) cin >> O[i];
  priority_queue<lli> que;
  Sort(P);
  Sort(Q);
  Sort(O);
  Rev(P);
  Rev(Q);
  Rev(O);
  rep(i, 0, A) rep(j, 0, B)
      rep(k, 0, C) if ((i + 1) * (j + 1) * (k + 1) < K + 1)
          que.push(P[i] + Q[j] + O[k]);
  rep(i, 0, K) {
    Out(que.top());
    que.pop();
  }
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
  ll x, y, z, k, a[1005], b[1005], c[1005];
  cin >> x >> y >> z >> k;
  for (int i = 0; i < x; i++)
    cin >> a[i];
  for (int i = 0; i < y; i++)
    cin >> b[i];
  for (int i = 0; i < z; i++)
    cin >> c[i];

  ll ab[1000005];
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      ab[y * i + j] = (a[i] + b[j]);
    }
  }
  sort(ab, ab + (x * y));
  reverse(ab, ab + (x * y));
  ll abc[3005];
  int l = min(x * y, k);
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < z; j++) {
      abc[z * i + j] = ab[i] + c[j];
    }
  }
  sort(abc, abc + l * z);
  reverse(abc, abc + l * z);
  for (int i = 0; i < k; i++) {
    cout << abc[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
  ll x, y, z, k, a[1005], b[1005], c[1005];
  cin >> x >> y >> z >> k;
  for (int i = 0; i < x; i++)
    cin >> a[i];
  for (int i = 0; i < y; i++)
    cin >> b[i];
  for (int i = 0; i < z; i++)
    cin >> c[i];

  ll ab[1000005];
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      ab[y * i + j] = (a[i] + b[j]);
    }
  }
  sort(ab, ab + (x * y));
  reverse(ab, ab + (x * y));
  ll abc[3000005];
  int l = min(x * y, k);
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < z; j++) {
      abc[z * i + j] = ab[i] + c[j];
    }
  }
  sort(abc, abc + l * z);
  reverse(abc, abc + l * z);
  for (int i = 0; i < k; i++) {
    cout << abc[i] << endl;
  }
  return 0;
}
Problem p03078 (C++)

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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int x, y, z, k;
ll a[1005], b[1005], c[1005];
ll sum1[1000005], sum2[1000005];
int num1, num2;
int main() {
  std::cin >> x >> y >> z >> k;
  for (int i = 0; i < x; ++i)
    std::cin >> a[i];
  for (int i = 0; i < y; ++i)
    std::cin >> b[i];
  for (int i = 0; i < z; ++i)
    std::cin >> c[i];

  std::sort(a, a + x, std::greater<ll>());
  std::sort(b, b + y, std::greater<ll>());
  std::sort(c, c + z, std::greater<ll>());

  for (int i = 0; i < x; ++i)
    for (int j = 0; j < y; ++j)
      sum1[num1++] = a[i] + b[j];

  std::sort(sum1, sum1 + num1, std::greater<ll>());

  for (int i = 0; i < k; ++i)
    for (int j = 0; j < z; ++j)
      sum2[num2++] = sum1[i] + c[j];

  std::sort(sum2, sum2 + num2, std::greater<ll>());

  for (int i = 0; i < k; ++i)
    std::cout << sum2[i] << std::endl;
  return 0;
}


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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int x, y, z, k;
ll a[1005], b[1005], c[1005];
ll sum1[10000005], sum2[10000005];
int num1, num2;
int main() {
  std::cin >> x >> y >> z >> k;
  for (int i = 0; i < x; ++i)
    std::cin >> a[i];
  for (int i = 0; i < y; ++i)
    std::cin >> b[i];
  for (int i = 0; i < z; ++i)
    std::cin >> c[i];

  std::sort(a, a + x, std::greater<ll>());
  std::sort(b, b + y, std::greater<ll>());
  std::sort(c, c + z, std::greater<ll>());

  for (int i = 0; i < x; ++i)
    for (int j = 0; j < y; ++j)
      sum1[num1++] = a[i] + b[j];

  std::sort(sum1, sum1 + num1, std::greater<ll>());

  for (int i = 0; i < k; ++i)
    for (int j = 0; j < z; ++j)
      sum2[num2++] = sum1[i] + c[j];

  std::sort(sum2, sum2 + num2, std::greater<ll>());

  for (int i = 0; i < k; ++i)
    std::cout << sum2[i] << std::endl;
  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define SIZE 200005
#define read(a, n)                                                             \
  for (i = 0; i < n; i++)                                                      \
    cin >> a[i];
#define pii pair<int, int>
#define pb push_back
#define forn for (i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll n, m, i, j, k, h, t, maxn, ttt, t1, t2, sig = 0;
multiset<ll> st;
ll a[1005], b[1005], c[1005];
bool cmp(ll a, ll b) { return a > b; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x, y, z;
  cin >> x >> y >> z >> t;
  read(a, x);
  read(b, y);
  read(c, z);
  sort(a, a + x, cmp);
  sort(b, b + y, cmp);
  sort(c, c + z, cmp);
  priority_queue<ll, vector<ll>, greater<ll>> q;
  for (i = 0; i < x; i++) {
    for (j = 0; j < y; j++) {
      for (k = 0; k < z; k++) {
        if (q.size() < t)
          q.push(a[i] + b[j] + c[k]);
        else {
          if (q.top() < a[i] + b[j] + c[k]) {
            q.pop();
            q.push(a[i] + b[j] + c[k]);
          }
        }
      }
    }
  }
  vector<ll> s(t + 1);
  j = 0;
  for (i = 0; i < t; i++) {
    s[j++] = q.top();
    q.pop();
  }
  for (i = 0; i < j; i++) {
    cout << s[j - i - 1] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define SIZE 200005
#define read(a, n)                                                             \
  for (i = 0; i < n; i++)                                                      \
    cin >> a[i];
#define pii pair<int, int>
#define pb push_back
#define forn for (i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll n, m, i, j, k, h, t, maxn, ttt, t1, t2, sig = 0;
multiset<ll> st;
ll a[1005], b[1005], c[1005];
bool cmp(ll a, ll b) { return a > b; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x, y, z;
  cin >> x >> y >> z >> t;
  read(a, x);
  read(b, y);
  read(c, z);
  sort(a, a + x, cmp);
  sort(b, b + y, cmp);
  sort(c, c + z, cmp);
  priority_queue<ll, vector<ll>, greater<ll>> q;
  for (i = 0; i < x; i++) {
    for (j = 0; j < y; j++) {
      for (k = 0; k < z; k++) {
        if (q.size() < t)
          q.push(a[i] + b[j] + c[k]);
        else {
          if (q.top() < a[i] + b[j] + c[k]) {
            q.pop();
            q.push(a[i] + b[j] + c[k]);
          } else
            break;
        }
      }
    }
  }
  vector<ll> s(t + 1);
  j = 0;
  for (i = 0; i < t; i++) {
    s[j++] = q.top();
    q.pop();
  }
  for (i = 0; i < j; i++) {
    cout << s[j - i - 1] << endl;
  }
  return 0;
}
Problem p03078 (C++)

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

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  vector<ll> e;
  rep(i, x) {
    rep(j, y) { e.push_back(a[i] + b[j]); }
  }
  sort(e.rbegin(), e.rend());
  // rep(i,x*y) cout << e[i] << endl;
  vector<ll> ans;
  rep(i, x * y) {
    rep(j, z) { ans.push_back(e[i] + c[j]); }
  }
  sort(ans.rbegin(), ans.rend());
  rep(i, k) cout << ans[i] << endl;
}

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

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  vector<ll> e;
  rep(i, x) {
    rep(j, y) { e.push_back(a[i] + b[j]); }
  }
  sort(e.rbegin(), e.rend());
  // rep(i,x*y) cout << e[i] << endl;
  vector<ll> ans;
  rep(i, min(x * y, k)) {
    rep(j, min(z, k)) { ans.push_back(e[i] + c[j]); }
  }
  sort(ans.rbegin(), ans.rend());
  rep(i, k) cout << ans[i] << endl;
}