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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
using namespace std;
typedef long long ll;

ll a[1000] = {};
ll b[1000] = {};
ll c[1000] = {};
ll D[1000000] = {};
ll E[1000000] = {};
int main() {
  ll x, y, z, k;
  cin >> x >> y >> z >> k;
  rep(i, 0, x) cin >> a[i];
  rep(i, 0, y) cin >> b[i];
  rep(i, 0, z) cin >> c[i];

  rep(i, 0, x) rep(j, 0, y) { D[i * y + j] = a[i] + b[j]; }
  sort(D, D + x * y);
  reverse(D, D + x * y);

  rep(i, 0, k) rep(j, 0, z) { E[i * z + j] = D[i] + c[j]; }

  sort(E, E + k * z);
  reverse(E, E + k * z);

  rep(i, 0, k) { cout << E[i] << endl; }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
using namespace std;
typedef long long ll;

ll a[1000] = {};
ll b[1000] = {};
ll c[1000] = {};
ll D[1000000] = {};
ll E[3000000] = {};
int main() {
  ll x, y, z, k;
  cin >> x >> y >> z >> k;
  rep(i, 0, x) cin >> a[i];
  rep(i, 0, y) cin >> b[i];
  rep(i, 0, z) cin >> c[i];

  rep(i, 0, x) rep(j, 0, y) { D[i * y + j] = a[i] + b[j]; }
  sort(D, D + x * y);
  reverse(D, D + x * y);

  rep(i, 0, k) rep(j, 0, z) { E[i * z + j] = D[i] + c[j]; }

  sort(E, E + k * z);
  reverse(E, E + k * z);

  rep(i, 0, k) { cout << E[i] << endl; }
  return 0;
}
Problem p03078 (C++)

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using lli = long long int;

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<lli> a(x);
  vector<lli> b(y);
  vector<lli> c(z);

  REP(i, x) cin >> a.at(i);
  REP(j, y) cin >> b.at(j);
  REP(k, z) cin >> c.at(k);

  vector<lli> ab(x * y);
  int idx = 0;
  REP(i, x) {
    REP(j, y) {
      ab.at(idx) = a.at(i) + b.at(j);
      idx++;
    }
  }

  sort(ab.rbegin(), ab.rend());

  vector<lli> abc(k * z);
  idx = 0;
  REP(i, k) {
    REP(j, z) {
      abc.at(idx) = ab.at(i) + c.at(j);
      idx++;
    }
  }

  sort(abc.rbegin(), abc.rend());
  REP(i, k) { cout << abc.at(i) << endl; }
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using lli = long long int;

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<lli> a(x);
  vector<lli> b(y);
  vector<lli> c(z);

  REP(i, x) cin >> a.at(i);
  REP(j, y) cin >> b.at(j);
  REP(k, z) cin >> c.at(k);

  vector<lli> ab(x * y);
  int idx = 0;
  REP(i, x) {
    REP(j, y) {
      ab.at(idx) = a.at(i) + b.at(j);
      idx++;
    }
  }

  sort(ab.rbegin(), ab.rend());

  vector<lli> abc(k * z);
  idx = 0;
  REP(i, min(x * y, k)) {
    REP(j, z) {
      abc.at(idx) = ab.at(i) + c.at(j);
      idx++;
    }
  }

  sort(abc.rbegin(), abc.rend());
  REP(i, k) { cout << abc.at(i) << endl; }
}
Problem p03078 (C++)

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

using namespace std;

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = 1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  VL a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];

  VL ab;
  ab.reserve(x * y + 5);
  rep(i, x) rep(j, y) ab.push_back(a[i] + b[j]);
  sort(all(ab), greater<ll>());

  VL ans;
  ans.reserve(sz(ab) * z + 5);
  rep(i, min(3001, sz(ab))) rep(j, z) ans.push_back(ab[i] + c[j]);
  sort(all(ans), greater<ll>());
  rep(i, k) { cout << ans[i] << "\n"; }

  return 0;
}


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

using namespace std;

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = 1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  VL a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];

  VL ab;
  ab.reserve(x * y + 5);
  rep(i, x) rep(j, y) ab.push_back(a[i] + b[j]);
  sort(all(ab), greater<ll>());

  VL ans;
  ans.reserve(min(3005, sz(ab)) * z + 5);
  rep(i, min(3001, sz(ab))) rep(j, z) ans.push_back(ab[i] + c[j]);
  sort(all(ans), greater<ll>());
  rep(i, k) { cout << ans[i] << "\n"; }

  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#define Rep(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) Rep(i, 0, b)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

/*
// 最大公約数
ll gcd(ll a, ll b) {
        if (b == 0) return a;
        return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
        return a * b / gcd(a, b);
}*/

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

  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> ab;

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

  sort(allof(ab), greater<ll>());

  vector<ll> abc;

  rep(i, x * y) {
    if (x * y == k)
      break;
    rep(j, z) {
      if (j == k)
        break;
      abc.push_back(ab[i] + c[j]);
    }
  }

  sort(allof(abc), greater<ll>());

  rep(i, k) { cout << abc[i] << endl; }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#define Rep(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) Rep(i, 0, b)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

/*
// 最大公約数
ll gcd(ll a, ll b) {
        if (b == 0) return a;
        return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
        return a * b / gcd(a, b);
}*/

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

  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> ab;

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

  sort(allof(ab), greater<ll>());

  vector<ll> abc;

  rep(i, x * y) {
    if (i == k)
      break;
    rep(j, z) {
      if (j == k)
        break;
      abc.push_back(ab[i] + c[j]);
    }
  }

  sort(allof(abc), greater<ll>());

  rep(i, k) { cout << abc[i] << endl; }

  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
// D.cpp
#include <bits/stdc++.h>
#define ll long long
#define pr pair<ll, ll>
using namespace std;
const int MAX_N = 1010;
ll seqA[MAX_N], seqB[MAX_N], seqC[MAX_N], x, y, z, k, current_seq[MAX_N << 2],
    tmp[MAX_N << 2];
struct node {
  ll val, ptr1, ptr2;
  bool operator<(const node &nd) const { return val < nd.val; }
};
priority_queue<node> pq;
bool cmp(ll a, ll b) { return a > b; }
void solve(ll *seq) {
  pq.push(node{current_seq[1] + seq[1], 1, 1});
  memset(tmp, 0, sizeof(tmp));
  for (int i = 1; i <= k && (!pq.empty()); i++) {
    node curt = pq.top();
    tmp[i] = curt.val, pq.pop();
    if (curt.ptr2 == 1 && current_seq[curt.ptr1 + 1] != 0)
      pq.push(node{current_seq[curt.ptr1 + 1] + seq[curt.ptr2], curt.ptr1 + 1,
                   curt.ptr2});
    if (seq[curt.ptr2 + 1] != 0)
      pq.push(node{current_seq[curt.ptr1] + seq[curt.ptr2 + 1], curt.ptr1,
                   curt.ptr2 + 1});
  }
  memcpy(current_seq, tmp, sizeof(tmp));
  while (!pq.empty())
    pq.pop();
}
int main() {
  scanf("%d%d%d%d", &x, &y, &z, &k);
  for (int i = 1; i <= x; i++)
    scanf("%lld", &seqA[i]);
  for (int i = 1; i <= y; i++)
    scanf("%lld", &seqB[i]);
  for (int i = 1; i <= z; i++)
    scanf("%lld", &seqC[i]);
  sort(seqA + 1, seqA + 1 + x, cmp), sort(seqB + 1, seqB + 1 + y, cmp),
      sort(seqC + 1, seqC + 1 + z, cmp);
  for (int i = 1; i <= k; i++)
    current_seq[i] = seqA[i];
  solve(seqB), solve(seqC);
  for (int i = 1; i <= k; i++)
    printf("%lld\n", current_seq[i]);
  return 0;
}

Fixed submission:
// D.cpp
#include <bits/stdc++.h>
#define ll long long
#define pr pair<ll, ll>
using namespace std;
const int MAX_N = 10100;
ll seqA[MAX_N], seqB[MAX_N], seqC[MAX_N], x, y, z, k, current_seq[MAX_N << 2],
    tmp[MAX_N << 2];
struct node {
  ll val, ptr1, ptr2;
  bool operator<(const node &nd) const { return val < nd.val; }
};
priority_queue<node> pq;
bool cmp(ll a, ll b) { return a > b; }
void solve(ll *seq) {
  pq.push(node{current_seq[1] + seq[1], 1, 1});
  memset(tmp, 0, sizeof(tmp));
  for (int i = 1; i <= k && (!pq.empty()); i++) {
    node curt = pq.top();
    tmp[i] = curt.val, pq.pop();
    if (curt.ptr2 == 1 && current_seq[curt.ptr1 + 1] != 0)
      pq.push(node{current_seq[curt.ptr1 + 1] + seq[curt.ptr2], curt.ptr1 + 1,
                   curt.ptr2});
    if (seq[curt.ptr2 + 1] != 0)
      pq.push(node{current_seq[curt.ptr1] + seq[curt.ptr2 + 1], curt.ptr1,
                   curt.ptr2 + 1});
  }
  memcpy(current_seq, tmp, sizeof(tmp));
  while (!pq.empty())
    pq.pop();
}
int main() {
  scanf("%d%d%d%d", &x, &y, &z, &k);
  for (int i = 1; i <= x; i++)
    scanf("%lld", &seqA[i]);
  for (int i = 1; i <= y; i++)
    scanf("%lld", &seqB[i]);
  for (int i = 1; i <= z; i++)
    scanf("%lld", &seqC[i]);
  sort(seqA + 1, seqA + 1 + x, cmp), sort(seqB + 1, seqB + 1 + y, cmp),
      sort(seqC + 1, seqC + 1 + z, cmp);
  for (int i = 1; i <= k; i++)
    current_seq[i] = seqA[i];
  solve(seqB), solve(seqC);
  for (int i = 1; i <= k; i++)
    printf("%lld\n", current_seq[i]);
  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

#define REP(i, n) for (int i = 0; i < n; ++i)

typedef unsigned long long u64;
typedef long long i64;

u64 x, y, z, k;
u64 a[1005];
u64 b[1005];
u64 c[1005];

u64 p[3005];
u64 q[3005];

u64 v[1000005];

void d(u64 s[1005], u64 s1, u64 t[1005], u64 t1, u64 u[3005]) {
  REP(i, s1) {
    REP(j, t1) { v[i * t1 + j] = s[i] + t[j]; }
  }

  sort(v, v + s1 * t1, greater<u64>());
  REP(i, k)
  u[i] = v[i];
}

void solve() {
  d(a, x, b, y, p);
  d(p, k, c, z, q);

  REP(i, k)
  cout << q[i] << endl;
}

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

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

  sort(a, a + x, greater<u64>());
  sort(b, b + x, greater<u64>());
  sort(c, c + x, greater<u64>());

  solve();

  return 0;
}


Fixed submission:
#include <algorithm>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

#define REP(i, n) for (int i = 0; i < n; ++i)

typedef unsigned long long u64;
typedef long long i64;

u64 x, y, z, k;
u64 a[1005];
u64 b[1005];
u64 c[1005];

u64 p[3005];
u64 q[3005];

u64 v[3000005];

void d(u64 s[1005], u64 s1, u64 t[1005], u64 t1, u64 u[3005]) {
  REP(i, s1) {
    REP(j, t1) { v[i * t1 + j] = s[i] + t[j]; }
  }

  sort(v, v + s1 * t1, greater<u64>());
  REP(i, k)
  u[i] = v[i];
}

void solve() {
  d(a, x, b, y, p);
  d(p, k, c, z, q);

  REP(i, k)
  cout << q[i] << endl;
}

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

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

  sort(a, a + x, greater<u64>());
  sort(b, b + x, greater<u64>());
  sort(c, c + x, greater<u64>());

  solve();

  return 0;
}
Problem p03078 (C++)

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

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

  int 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];

  vector<long long> tastes;
  for (int i = 0; i < X; ++i)
    for (int j = 0; j < Y; ++j)
      tastes.push_back(A[i] + B[j]);
  sort(tastes.begin(), tastes.end(), greater<long long>());

  vector<long long> ans;
  for (int i = 0; i < Z; ++i)
    for (long long taste : tastes)
      ans.push_back(taste + C[i]);
  sort(ans.begin(), ans.end(), greater<long long>());

  for (int i = 0; i < K; ++i)
    cout << ans[i] << "\n";

  return 0;
}

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

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

  int 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];

  vector<long long> tastes;
  for (int i = 0; i < X; ++i)
    for (int j = 0; j < Y; ++j)
      tastes.push_back(A[i] + B[j]);
  sort(tastes.begin(), tastes.end(), greater<long long>());

  vector<long long> ans;
  for (int i = 0; i < Z; ++i)
    for (int j = 0; j < min((int)tastes.size(), K); ++j)
      ans.push_back(tastes[j] + C[i]);
  sort(ans.begin(), ans.end(), greater<long long>());

  for (int i = 0; i < K; ++i)
    cout << ans[i] << "\n";

  return 0;
}
Problem p03078 (C++)

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

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int x, y, z, k;
  cin >> x >> y >> z >> k;
  ll 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<ll>());
  sort(b, b + y, greater<ll>());
  sort(c, c + z, greater<ll>());
  vector<ll> ans;
  for (int i = 0; i < min(x, 500); i++) {
    for (int j = 0; j < min(y, 500); j++) {
      for (int l = 0; l < min(z, 500); l++) {
        ll sum = a[i] + b[j] + c[l];
        ans.pb(sum);
      }
    }
  }
  sort(all(ans), greater<ll>());
  for (auto it : ans) {
    if (k == 0) {
      break;
    }
    cout << it << "\n";
    k--;
  }
}

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

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int x, y, z, k;
  cin >> x >> y >> z >> k;
  ll 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<ll>());
  sort(b, b + y, greater<ll>());
  sort(c, c + z, greater<ll>());
  vector<ll> ans;
  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) {
          ll sum = a[i] + b[j] + c[l];
          ans.pb(sum);
        } else {
          break;
        }
      }
    }
  }
  sort(all(ans), greater<ll>());
  for (auto it : ans) {
    if (k == 0) {
      break;
    }
    cout << it << "\n";
    k--;
  }
}
Problem p03078 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool cmp(long long int a, long long int b) { return a > b; }
int main() {
  long long int x, y, z, k, t;
  cin >> x >> y >> z >> k;
  vector<long long int> a, b, c, d, e;
  for (long long int i = 0; i < x; i++) {
    cin >> t;
    a.push_back(t);
  }
  for (long long int i = 0; i < y; i++) {
    cin >> t;
    b.push_back(t);
  }
  for (long long int i = 0; i < z; i++) {
    cin >> t;
    c.push_back(t);
  }
  sort(a.begin(), a.end(), cmp);
  sort(b.begin(), b.end(), cmp);
  sort(c.begin(), c.end(), cmp);
  for (long long int i = 0; i < min(k, x); i++) {
    for (long long int j = 0; j < min(k, y); j++) {
      d.push_back(a[i] + b[j]);
    }
  }
  sort(d.begin(), d.end(), cmp);
  for (long long int i = 0; i < d.size(); i++) {
    for (long long int j = 0; j < min(k, z); j++) {
      e.push_back(d[i] + c[j]);
    }
  }
  sort(e.begin(), e.end(), cmp);
  for (long long int i = 0; i < k; i++)
    cout << e[i] << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool cmp(long long int a, long long int b) { return a > b; }
int main() {
  long long int x, y, z, k, t;
  cin >> x >> y >> z >> k;
  vector<long long int> a, b, c, d, e;
  for (long long int i = 0; i < x; i++) {
    cin >> t;
    a.push_back(t);
  }
  for (long long int i = 0; i < y; i++) {
    cin >> t;
    b.push_back(t);
  }
  for (long long int i = 0; i < z; i++) {
    cin >> t;
    c.push_back(t);
  }
  sort(a.begin(), a.end(), cmp);
  sort(b.begin(), b.end(), cmp);
  sort(c.begin(), c.end(), cmp);
  for (long long int i = 0; i < min(k, x); i++) {
    for (long long int j = 0; j < min(k, y); j++) {
      d.push_back(a[i] + b[j]);
    }
  }
  sort(d.begin(), d.end(), cmp);
  long long int size = d.size();
  for (long long int i = 0; i < min(size, k); i++) {
    for (long long int j = 0; j < min(k, z); j++) {
      e.push_back(d[i] + c[j]);
    }
  }
  sort(e.begin(), e.end(), cmp);
  for (long long int i = 0; i < k; i++)
    cout << e[i] << endl;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

ll X, Y, Z, K;
ll A[1010], B[1010], C[1010];

ll D[1000100];

ll E[3010];

int main() {
  cin >> X >> Y >> Z >> K;
  for (ll i = 0; i < X; i++) {
    cin >> A[i];
  }
  for (ll i = 0; i < Y; i++) {
    cin >> B[i];
  }
  for (ll 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>());

  ll i_d = 0;

  for (ll i = 0; i < X; i++) {
    for (ll j = 0; j < Y; j++) {
      D[i_d++] = A[i] + B[j];
    }
  }

  sort(D, D + i_d, greater<ll>());

  ll i_e = 0;

  for (ll i = 0; i < K; i++) {
    for (ll j = 0; j < Z; j++) {
      E[i_e++] = D[i] + C[j];
    }
  }

  sort(E, E + i_e, greater<ll>());

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

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

ll X, Y, Z, K;
ll A[1010], B[1010], C[1010];

ll D[1000100];

ll E[3000100];

int main() {
  cin >> X >> Y >> Z >> K;
  for (ll i = 0; i < X; i++) {
    cin >> A[i];
  }
  for (ll i = 0; i < Y; i++) {
    cin >> B[i];
  }
  for (ll 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>());

  ll i_d = 0;

  for (ll i = 0; i < X; i++) {
    for (ll j = 0; j < Y; j++) {
      D[i_d++] = A[i] + B[j];
    }
  }

  sort(D, D + i_d, greater<ll>());

  ll i_e = 0;

  for (ll i = 0; i < K; i++) {
    for (ll j = 0; j < Z; j++) {
      E[i_e++] = D[i] + C[j];
    }
  }

  sort(E, E + i_e, greater<ll>());

  for (ll i = 0; i < K; i++) {
    cout << E[i] << endl;
  }
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
  int X, Y, Z, K;
  std::cin >> X >> Y >> Z >> K;
  std::vector<long long> A(X);
  std::vector<long long> B(Y);
  std::vector<long long> C(Z);
  std::vector<long long> AB;
  std::vector<long long> ABt;
  std::vector<long long> ABC;
  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];
  ;

  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      AB.push_back(A[i] + B[j]);
    }
  }
  sort(AB.begin(), AB.end());
  reverse(AB.begin(), AB.end());
  ABt.assign(&AB[0], &AB[K - 1]);
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < Z; j++) {
      ABC.push_back(ABt[i] + C[j]);
    }
  }
  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());
  for (int i = 0; i < K; i++)
    std::cout << ABC[i] << '\n';
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
  int X, Y, Z, K;
  std::cin >> X >> Y >> Z >> K;
  std::vector<long long> A(X);
  std::vector<long long> B(Y);
  std::vector<long long> C(Z);
  std::vector<long long> AB;
  std::vector<long long> ABt;
  std::vector<long long> ABC;
  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];
  ;

  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      AB.push_back(A[i] + B[j]);
    }
  }
  sort(AB.begin(), AB.end());
  reverse(AB.begin(), AB.end());
  for (int i = 0; i < min(X * Y, K); i++)
    ABt.push_back(AB[i]);
  for (int i = 0; i < min(X * Y, K); i++) {
    for (int j = 0; j < Z; j++) {
      ABC.push_back(ABt[i] + C[j]);
    }
  }
  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());
  for (int i = 0; i < K; i++)
    std::cout << ABC[i] << '\n';
  return 0;
}
Problem p03078 (C++)

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

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

  ll 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, k) { cin >> C[i]; }
  vector<ll> AB(max(3000ll, x * y));
  rep(i, x) {
    rep(j, y) { AB[y * i + j] = A[i] + B[j]; }
  }
  sort(AB.begin(), AB.end(), greater<ll>());
  vector<ll> ABC(AB.size() * y);
  rep(i, 3000) {
    rep(j, y) { ABC[i * y + j] = AB[i] + C[j]; }
  }
  sort(ABC.begin(), ABC.end(), greater<ll>());

  rep(i, k) { cout << ABC[i] << "\n"; }

  return 0;
}

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

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

  ll 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, k) { cin >> C[i]; }
  vector<ll> AB(max(3000ll, x * y));
  rep(i, x) {
    rep(j, y) { AB[y * i + j] = A[i] + B[j]; }
  }
  sort(AB.begin(), AB.end(), greater<ll>());
  vector<ll> ABC(3000 * y);
  rep(i, 3000) {
    rep(j, y) { ABC[i * y + j] = AB[i] + C[j]; }
  }
  sort(ABC.begin(), ABC.end(), greater<ll>());

  rep(i, k) { cout << ABC[i] << "\n"; }

  return 0;
}
Problem p03078 (C++)

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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> X >> K;
  vll A(X), B(Y), C(Z);
  for (int i = 0; i < X; ++i) {
    ll a;
    cin >> a;
    A[i] = a;
  }
  for (int i = 0; i < Y; ++i) {
    ll b;
    cin >> b;
    B[i] = b;
  }
  for (int i = 0; i < Z; ++i) {
    ll c;
    cin >> c;
    C[i] = c;
  }

  vll partial_sum;
  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      ll s = A[i] + B[j];
      partial_sum.push_back(s);
    }
  }

  sort(partial_sum.begin(), partial_sum.end(), greater<ll>());
  vll ans;

  int K_ = min(K, X * Y);
  for (int i = 0; i < K_; ++i) {
    for (int j = 0; j < Z; ++j) {
      ll t = partial_sum[i] + C[j];
      ans.push_back(t);
    }
  }

  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;
typedef long long ll;
typedef vector<ll> vll;

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vll A(X), B(Y), C(Z);
  for (int i = 0; i < X; ++i) {
    ll a;
    cin >> a;
    A[i] = a;
  }
  for (int i = 0; i < Y; ++i) {
    ll b;
    cin >> b;
    B[i] = b;
  }
  for (int i = 0; i < Z; ++i) {
    ll c;
    cin >> c;
    C[i] = c;
  }

  vll partial_sum;
  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      ll s = A[i] + B[j];
      partial_sum.push_back(s);
    }
  }

  sort(partial_sum.begin(), partial_sum.end(), greater<ll>());
  vll ans;

  int K_ = min(K, X * Y);
  for (int i = 0; i < K_; ++i) {
    for (int j = 0; j < Z; ++j) {
      ll t = partial_sum[i] + C[j];
      ans.push_back(t);
    }
  }

  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: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vll A, B, C;
  for (int i = 0; i < X; ++i) {
    ll a;
    cin >> a;
    A.push_back(a);
  }
  for (int i = 0; i < Y; ++i) {
    ll b;
    cin >> b;
    B.push_back(b);
  }
  for (int i = 0; i < Z; ++i) {
    ll c;
    cin >> c;
    C.push_back(c);
  }

  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());
  sort(C.begin(), C.end(), greater<ll>());
  vll D;

  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      D.push_back(A[i] + B[j]);
    }
  }

  sort(D.begin(), D.end(), greater<ll>());
  vll E;

  int K_ = min(K, X * Y);

  for (int i = 0; i < K_; ++i) {
    for (int j = 0; j < Z; ++j) {
      E.push_back(D[i] + E[j]);
    }
  }

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

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

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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vll A, B, C;
  for (int i = 0; i < X; ++i) {
    ll a;
    cin >> a;
    A.push_back(a);
  }
  for (int i = 0; i < Y; ++i) {
    ll b;
    cin >> b;
    B.push_back(b);
  }
  for (int i = 0; i < Z; ++i) {
    ll c;
    cin >> c;
    C.push_back(c);
  }

  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());
  sort(C.begin(), C.end(), greater<ll>());
  vll D;

  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      D.push_back(A[i] + B[j]);
    }
  }

  sort(D.begin(), D.end(), greater<ll>());
  vll E;

  int K_ = min(K, X * Y);

  for (int i = 0; i < K_; ++i) {
    for (int j = 0; j < Z; ++j) {
      E.push_back(D[i] + C[j]);
    }
  }

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

  for (int i = 0; i < K; ++i) {
    cout << E[i] << endl;
  }
  return 0;
}
Problem p03078 (C++)

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

long long X, Y, Z, K, A[1009], B[1009], C[1009];
vector<long long> vec;

int main() {
  cin >> X >> Y >> Z >> K;
  for (int i = 0; i < X; i++)
    cin >> A[i];
  sort(A, A + X, greater<long long>());
  for (int i = 0; i < Y; i++)
    cin >> B[i];
  sort(B, B + Y, greater<long long>());
  for (int i = 0; i < Z; i++)
    cin >> C[i];
  sort(C, C + Z, greater<long long>());

  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        if ((i + 1) * (j + 1) * (k + 1) <= K)
          vec.push_back(A[i] + B[j] + C[k]);
        else
          break;
      }
    }
  }
  sort(vec.begin(), vec.end(), greater<long long>());
  for (int i = 0; i < K; i++)
    cout << vec[i] << endl;
  return 0;
}


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

long long X, Y, Z, K, A[1009], B[1009], C[1009];
vector<long long> vec;

int main() {
  cin >> X >> Y >> Z >> K;
  for (int i = 0; i < X; i++)
    cin >> A[i];
  sort(A, A + X, greater<long long>());
  for (int i = 0; i < Y; i++)
    cin >> B[i];
  sort(B, B + Y, greater<long long>());
  for (int i = 0; i < Z; i++)
    cin >> C[i];
  sort(C, C + Z, greater<long long>());

  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      for (int k = 0; k < Z; k++) {
        if ((i + 1) * (j + 1) * (k + 1) <= K)
          vec.push_back(A[i] + B[j] + C[k]);
        else
          break;
      }
    }
  }
  sort(vec.begin(), vec.end(), greater<long long>());
  for (int i = 0; i < K; i++)
    cout << vec[i] << endl;
  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for (int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for (int i = s; i <= e; i++)
#define FORR(i, s, e) for (int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<LLI> a(X), b(Y), c(Z);
  REP(i, X) { cin >> a[i]; }
  RSORT(a);
  REP(i, Y) { cin >> b[i]; }
  RSORT(b);
  REP(i, Z) { cin >> c[i]; }
  RSORT(c);

  vector<LLI> v;
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      for (int k = 0; k < Z; k++) {
        if ((i + 1) * (j + 1) * (k + 1) < K)
          v.push_back(a[i] + b[j] + c[k]);
        else
          break;
      }
    }
  }
  RSORT(v);
  REP(i, K) { cout << v[i] << endl; }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for (int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for (int i = s; i <= e; i++)
#define FORR(i, s, e) for (int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<LLI> a(X), b(Y), c(Z);
  REP(i, X) { cin >> a[i]; }
  RSORT(a);
  REP(i, Y) { cin >> b[i]; }
  RSORT(b);
  REP(i, Z) { cin >> c[i]; }
  RSORT(c);

  vector<LLI> v;
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      for (int k = 0; k < Z; k++) {
        if ((i + 1) * (j + 1) * (k + 1) <= K)
          v.push_back(a[i] + b[j] + c[k]);
        else
          break;
      }
    }
  }
  RSORT(v);
  REP(i, K) { cout << v[i] << endl; }

  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef int64_t SI;
typedef uint64_t UI;

void read(SI &N, vector<SI> &V) {
  cin >> N;
  V.resize(N);
  for (size_t i = 0; i < N; i++) {
    SI x;
    cin >> x;
    V[i] = x;
  }
}

int solve(const vector<SI> &V) { return 0; }

void test() {
  {
    vector<UI> A = {4, 6};
    vector<UI> B = {1, 5};
    vector<UI> C = {3, 8};
    UI K = 8;
    vector<SI> V = {0, 1, 2};
    assert(solve(V) == 0);
  }
  cerr << "OK" << endl;
}

int main() {
  UI X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<UI> A(X), B(Y), C(Z);
  for (SI i = 0; i < X; i++) {
    cin >> A[i];
  }
  for (SI i = 0; i < Y; i++) {
    cin >> B[i];
  }
  for (SI i = 0; i < Z; i++) {
    cin >> C[i];
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());

  vector<UI> ABC;
  for (size_t i = 0; i < X; i++) {
    for (size_t j = 0; j < Y; j++) {
      if ((i + 1) * (j + 1) > K)
        break;
      for (size_t k = 0; k < Z; k++) {
        if ((i + 1) * (j + 1) + (k + 1) > K)
          break;
        ABC.push_back(A[i] + B[j] + C[k]);
      }
    }
  }

  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());

  for (size_t i = 0; i < K; i++) {
    cout << ABC[i] << std::endl;
  }

  return 0;
}


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

using namespace std;
typedef int64_t SI;
typedef uint64_t UI;

void read(SI &N, vector<SI> &V) {
  cin >> N;
  V.resize(N);
  for (size_t i = 0; i < N; i++) {
    SI x;
    cin >> x;
    V[i] = x;
  }
}

int solve(const vector<SI> &V) { return 0; }

void test() {
  {
    vector<UI> A = {4, 6};
    vector<UI> B = {1, 5};
    vector<UI> C = {3, 8};
    UI K = 8;
    vector<SI> V = {0, 1, 2};
    assert(solve(V) == 0);
  }
  cerr << "OK" << endl;
}

int main() {
  UI X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<UI> A(X), B(Y), C(Z);
  for (SI i = 0; i < X; i++) {
    cin >> A[i];
  }
  for (SI i = 0; i < Y; i++) {
    cin >> B[i];
  }
  for (SI i = 0; i < Z; i++) {
    cin >> C[i];
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());

  vector<UI> ABC;
  for (size_t i = 0; i < X; i++) {
    for (size_t j = 0; j < Y; j++) {
      if ((i + 1) * (j + 1) > K)
        break;
      for (size_t k = 0; k < Z; k++) {
        if ((i + 1) * (j + 1) * (k + 1) > K)
          break;
        ABC.push_back(A[i] + B[j] + C[k]);
      }
    }
  }

  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());

  for (size_t i = 0; i < K; i++) {
    cout << ABC[i] << std::endl;
  }

  return 0;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<long long> A(x);
  vector<long long> B(y);
  vector<long long> 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.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  vector<long long> AB(x * y);
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      AB[i * y + j] = A[i] + B[j];
    }
  }
  sort(AB.begin(), AB.end());
  reverse(AB.begin(), AB.end());
  int s = max(3000, x * y);
  vector<long long> ABC(s * z);
  for (int i = 0; i < s; i++) {
    for (int j = 0; j < z; j++) {
      ABC[i * z + j] = AB[i] + C[j];
    }
  }
  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());
  for (int i = 0; i < k; i++) {
    cout << ABC[i] << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<long long> A(x);
  vector<long long> B(y);
  vector<long long> 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.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  vector<long long> AB(x * y);
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      AB[i * y + j] = A[i] + B[j];
    }
  }
  sort(AB.begin(), AB.end());
  reverse(AB.begin(), AB.end());
  int s = min(k, x * y);
  vector<long long> ABC(s * z);
  for (int i = 0; i < s; i++) {
    for (int j = 0; j < z; j++) {
      ABC[i * z + j] = AB[i] + C[j];
    }
  }
  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());
  for (int i = 0; i < k; i++) {
    cout << ABC[i] << endl;
  }
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> 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.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.rbegin(), C.rend());
  vector<ll> ans;
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      for (int k = 0; k < Z; k++) {
        if ((i + 1) * (j + 1) * (k + 1) >= K)
          break;
        ans.push_back(A[i] + B[j] + C[k]);
      }
    }
  }
  sort(ans.rbegin(), ans.rend());
  for (int i = 0; i < K; i++) {
    cout << ans[i] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> 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.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.rbegin(), C.rend());
  vector<ll> ans;
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      for (int k = 0; k < Z; k++) {
        if ((i + 1) * (j + 1) * (k + 1) > K)
          break;
        ans.push_back(A[i] + B[j] + C[k]);
      }
    }
  }
  sort(ans.rbegin(), ans.rend());
  for (int i = 0; i < K; i++) {
    cout << ans[i] << endl;
  }
}
Problem p03078 (C++)

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

int main() {
  int x, y, z, q;
  cin >> x >> y >> z >> q;
  vector<long long> a(x), b(y), c(z);
  rep(i, x) cin >> a.at(i);
  rep(i, y) cin >> b.at(i);
  rep(i, z) cin >> c.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());
  vector<long long> u(0);
  rep(i, x) {
    rep(j, y) {
      rep(k, z) {
        if (x * y * z > 3000)
          break;
        u.push_back(a.at(i) + b.at(j) + c.at(k));
      }
    }
  }
  sort(u.begin(), u.end());
  reverse(u.begin(), u.end());
  rep(i, q) { cout << u.at(i) << endl; }
}

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

int main() {
  int x, y, z, q;
  cin >> x >> y >> z >> q;
  vector<long long> a(x), b(y), c(z);
  rep(i, x) cin >> a.at(i);
  rep(i, y) cin >> b.at(i);
  rep(i, z) cin >> c.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());
  vector<long long> u(0);
  rep(i, x) {
    rep(j, y) {
      rep(k, z) {
        if (i * j * k > 3000)
          break;
        u.push_back(a.at(i) + b.at(j) + c.at(k));
      }
    }
  }
  sort(u.begin(), u.end());
  reverse(u.begin(), u.end());
  rep(i, q) { cout << u.at(i) << endl; }
}
Problem p03078 (C++)

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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  long A[X], B[Y], C[Z];
  vector<long> A_and_B, result;
  for (int i = 0; i < K; i++) {
    A_and_B[i] = 0;
    result[i] = 0;
  }
  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];

  for (int i = 0; i < X; i++)
    for (int j = 0; j < Y; j++)
      A_and_B.push_back(A[i] + B[j]);
  sort(A_and_B.begin(), A_and_B.end(), greater<>());
  A_and_B.resize(K);

  for (int i = 0; i < K; i++)
    for (int j = 0; j < Z; j++)
      result.push_back(A_and_B[i] + C[j]);
  sort(result.begin(), result.end(), greater<>());
  result.resize(K);

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

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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  long A[X], B[Y], C[Z];
  vector<long> A_and_B, result;
  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];

  for (int i = 0; i < X; i++)
    for (int j = 0; j < Y; j++)
      A_and_B.push_back(A[i] + B[j]);
  sort(A_and_B.begin(), A_and_B.end(), greater<>());
  A_and_B.resize(K);

  for (int i = 0; i < K; i++)
    for (int j = 0; j < Z; j++)
      result.push_back(A_and_B[i] + C[j]);
  sort(result.begin(), result.end(), greater<>());
  result.resize(K);

  for (int i = 0; i < K; i++)
    cout << result[i] << endl;
}
Problem p03078 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define MAX(A) *max_element(A.begin(), A.end())
#define MIN(A) *min_element(A.begin(), A.end())
#define SORT(A) sort(A.begin(), A.end())
#define REV(A) reverse(A.begin(), A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int, int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
  int nx, ny, nz, k;
  cin >> nx >> ny >> nz >> k;
  vll a(nx), b(ny), c(nz);
  rep(ix, nx) cin >> a[ix];
  rep(iy, ny) cin >> b[iy];
  rep(iz, nz) cin >> c[iz];
  vll e;
  rep(ix, nx) rep(iy, ny) e.push_back(a[ix] + b[iy]);
  SORT(e);
  REV(e);
  vll f;
  rep(ie, nx * ny) rep(iz, nz) f.push_back(e[ie] + c[iz]);
  SORT(f);
  REV(f);
  rep(i, k) cout << f[i] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define MAX(A) *max_element(A.begin(), A.end())
#define MIN(A) *min_element(A.begin(), A.end())
#define SORT(A) sort(A.begin(), A.end())
#define REV(A) reverse(A.begin(), A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int, int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
  int nx, ny, nz, k;
  cin >> nx >> ny >> nz >> k;
  vll a(nx), b(ny), c(nz);
  rep(ix, nx) cin >> a[ix];
  rep(iy, ny) cin >> b[iy];
  rep(iz, nz) cin >> c[iz];
  vll e;
  rep(ix, nx) rep(iy, ny) e.push_back(a[ix] + b[iy]);
  SORT(e);
  REV(e);
  vll f;
  rep(ie, min(k, nx * ny)) rep(iz, nz) f.push_back(e[ie] + c[iz]);
  SORT(f);
  REV(f);
  rep(i, k) cout << f[i] << endl;
}
Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int x, y, z, kk;
long long a[1005], b[1005], c[1005];
long long ans[10005];
int cur = 0;

bool cmp(long long a1, long long a2) { return a1 > a2; }

int main()

{
  ios::sync_with_stdio(false);
  cin >> x >> y >> z >> kk;
  for (int i = 1; i <= x; i++)
    cin >> a[i];
  for (int i = 1; i <= y; i++)
    cin >> b[i];
  for (int i = 1; i <= z; i++)
    cin >> c[i];

  sort(a + 1, a + 1 + x, cmp);
  sort(b + 1, b + 1 + y, cmp);
  sort(c + 1, c + 1 + z, cmp);

  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      for (int k = 1; k <= z; k++) {
        if (i * j * k > kk)
          break;
        ans[++cur] = a[i] + b[j] + c[k];
      }
    }
  }

  sort(ans + 1, ans + cur + 1, cmp);
  for (int i = 1; i <= kk; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int x, y, z, kk;
long long a[1005], b[1005], c[1005];
long long ans[1000005];
int cur = 0;

bool cmp(long long a1, long long a2) { return a1 > a2; }

int main()

{
  ios::sync_with_stdio(false);
  cin >> x >> y >> z >> kk;
  for (int i = 1; i <= x; i++)
    cin >> a[i];
  for (int i = 1; i <= y; i++)
    cin >> b[i];
  for (int i = 1; i <= z; i++)
    cin >> c[i];

  sort(a + 1, a + 1 + x, cmp);
  sort(b + 1, b + 1 + y, cmp);
  sort(c + 1, c + 1 + z, cmp);

  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      for (int k = 1; k <= z; k++) {
        if (i * j * k > kk)
          break;
        ans[++cur] = a[i] + b[j] + c[k];
      }
    }
  }

  sort(ans + 1, ans + cur + 1, cmp);
  for (int i = 1; i <= kk; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}