Problem p03078 (C++)

Buggy submission (status: Runtime Error):
#pragma region _head

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#pragma region _define

#define int LL
#define f(i, a, b) for (LL i = a; i < b; i++)
#define f_vI(v, n) f(i, 0, n) cin >> v[i]
#define f_v2I(v1, v2, n) f(i, 0, n) cin >> v1[i] >> v2[i]
#define f_v3I(v1, v2, v3, n) f(i, 0, n) cin >> v1[i] >> v2[i] >> v3[i]
#define f_vO(v, n) f(i, 0, n) cout << v[i] << endl
#define ei else if
#define all(a) a.begin(), a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout << "! ! !"
#define endl "\n"
#define _y() cout << "Yes" << endl
#define _Y() cout << "YES" << endl
#define _n() cout << "No" << endl
#define _N() cout << "NO" << endl
#define int_INF 1 << 29
#define ll_INF 1LL << 60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50 // グラフの最大位数　適宜変更
// bool graph[node][node]; bool visited[node] = { false };
#define link(a, b, m)                                                          \
  f(i, 0, m) {                                                                 \
    cin >> a[i] >> b[i];                                                       \
    a[i]--;                                                                    \
    b[i]--;                                                                    \
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;                              \
  }

#pragma endregion

void _yn(bool p) { p ? _y() : _n(); }

void _YN(bool p) { p ? _Y() : _N(); }

LL gcd(LL a, LL b) {
  LL r;
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}
LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); }

// 素数判定
bool is_prime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

// 階乗計算
LL factorial(LL n) {
  LL a = 1, ret = 1;
  while (a < n) {
    a++;
    ret *= a;
    ret %= MOD;
  }
  return ret;
}

#pragma endregion

/*****************************************************************************/

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

  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vi a(x), b(y), c(z);
  f_vI(a, x);
  f_vI(b, y);
  f_vI(c, z);
  sort(all(a), greater<int>());
  sort(all(b), greater<int>());
  sort(all(c), greater<int>());
  vi ans;
  f(i, 0, x) {
    f(j, 0, y) {
      f(o, 0, z) { ans.push_back(a[i] + b[j] + c[o]); }
    }
  }
  sort(all(ans), greater<int>());
  f(i, 0, k) { cout << ans[i] << endl; }
  return 0;
}

Fixed submission:
#pragma region _head

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#pragma region _define

#define int LL
#define f(i, a, b) for (LL i = a; i < b; i++)
#define f_vI(v, n) f(i, 0, n) cin >> v[i]
#define f_v2I(v1, v2, n) f(i, 0, n) cin >> v1[i] >> v2[i]
#define f_v3I(v1, v2, v3, n) f(i, 0, n) cin >> v1[i] >> v2[i] >> v3[i]
#define f_vO(v, n) f(i, 0, n) cout << v[i] << endl
#define ei else if
#define all(a) a.begin(), a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout << "! ! !"
#define endl "\n"
#define _y() cout << "Yes" << endl
#define _Y() cout << "YES" << endl
#define _n() cout << "No" << endl
#define _N() cout << "NO" << endl
#define int_INF 1 << 29
#define ll_INF 1LL << 60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50 // グラフの最大位数　適宜変更
// bool graph[node][node]; bool visited[node] = { false };
#define link(a, b, m)                                                          \
  f(i, 0, m) {                                                                 \
    cin >> a[i] >> b[i];                                                       \
    a[i]--;                                                                    \
    b[i]--;                                                                    \
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;                              \
  }

#pragma endregion

void _yn(bool p) { p ? _y() : _n(); }

void _YN(bool p) { p ? _Y() : _N(); }

LL gcd(LL a, LL b) {
  LL r;
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}
LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); }

// 素数判定
bool is_prime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

// 階乗計算
LL factorial(LL n) {
  LL a = 1, ret = 1;
  while (a < n) {
    a++;
    ret *= a;
    ret %= MOD;
  }
  return ret;
}

#pragma endregion

/*****************************************************************************/

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

  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vi a(x), b(y), c(z);
  f_vI(a, x);
  f_vI(b, y);
  f_vI(c, z);
  sort(all(a), greater<int>());
  sort(all(b), greater<int>());
  sort(all(c), greater<int>());
  vi ans;
  f(i, 0, x) {
    f(j, 0, y) {
      f(o, 0, z) {
        if ((i + 1) * (j + 1) * (o + 1) <= k) {
          ans.push_back(a[i] + b[j] + c[o]);
        }
      }
    }
  }
  sort(all(ans), greater<int>());
  f(i, 0, k) { cout << ans[i] << endl; }
  return 0;
}