Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize(                                                          \
    "Ofast") // Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  cout << fixed;                                                               \
  cout << setprecision(10);
#define randomINIT                                                             \
  mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define foo(i, a, n) for (ll i = (a); i <= n; i++)
#define frr(i, a, n) for (ll i = (a); i >= n; i--)
#define fo(i, n) for (ll i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define mset(x, val) memset(x, val, sizeof(x))
#define newl cout << "\n"
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define dline cerr << "///REACHED///\n";
#define deb1(x) cerr << #x << " = " << x << '\n';
#define deb2(x, y)                                                             \
  cerr << '[' << #x << ',' << #y << "] = " << '[' << x << ',' << y << ']'      \
       << '\n';
#define deb3(x, y, z)                                                          \
  cerr << '[' << #x << ',' << #y << ',' << #z << "] = " << '[' << x << ','     \
       << y << ',' << z << ']' << '\n';

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const ll MOD = 1e+9 + 7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MAXN = 1e+5 + 7;

vll adj[MAXN];
ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

//<<-----Declare Variable Here------->>//
int t = 1;
ll x, y, a, b, c, h;
vll v1, v2, v3, v4;
//<<-----Implement Functions Here---->>//

//<<-----Start of Main--------------->>//
void MAIN() {
  cin >> x >> y >> a >> b >> c;
  for (ll i = 0; i < a; i++)
    cin >> h, v1.pb(h);
  for (ll i = 0; i < b; i++)
    cin >> h, v2.pb(h);
  for (ll i = 0; i < c; i++)
    cin >> h, v3.pb(h);
  sort(all(v1));
  reverse(all(v1));
  sort(all(v2));
  reverse(all(v2));
  sort(all(v3));
  reverse(all(v3));
  for (ll i = 0; i < x; i++)
    v4.pb(v1[i]);
  for (ll i = 0; i < y; i++)
    v4.pb(v2[i]);
  sort(all(v4));
  ll len = min(x + y, c);
  for (ll i = 0; i < len; i++) {
    if (v3[i] > v4[i])
      v4[i] = v3[i];
    else
      break;
  }
  ll sum1 = 0;
  for (ll i = 0; i < x + y; i++)
    sum1 += v4[i];
  cout << sum1;
}

int main() {
  fastio;
  randomINIT;

  // cin>>t;
  while (t--) {
    MAIN();
  }
}

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  cout << fixed;                                                               \
  cout << setprecision(10);
#define randomINIT                                                             \
  mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define foo(i, a, n) for (ll i = (a); i <= n; i++)
#define frr(i, a, n) for (ll i = (a); i >= n; i--)
#define fo(i, n) for (ll i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define mset(x, val) memset(x, val, sizeof(x))
#define newl cout << "\n"
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define dline cerr << "///REACHED///\n";
#define deb1(x) cerr << #x << " = " << x << '\n';
#define deb2(x, y)                                                             \
  cerr << '[' << #x << ',' << #y << "] = " << '[' << x << ',' << y << ']'      \
       << '\n';
#define deb3(x, y, z)                                                          \
  cerr << '[' << #x << ',' << #y << ',' << #z << "] = " << '[' << x << ','     \
       << y << ',' << z << ']' << '\n';

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const ll MOD = 1e+9 + 7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MAXN = 1e+5 + 7;

vll adj[MAXN];
ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

//<<-----Declare Variable Here------->>//
int t = 1;
ll x, y, a, b, c, h;
vll v1, v2, v3, v4;
//<<-----Implement Functions Here---->>//

//<<-----Start of Main--------------->>//
void MAIN() {
  cin >> x >> y >> a >> b >> c;
  for (ll i = 0; i < a; i++)
    cin >> h, v1.pb(h);
  for (ll i = 0; i < b; i++)
    cin >> h, v2.pb(h);
  for (ll i = 0; i < c; i++)
    cin >> h, v3.pb(h);
  sort(all(v1));
  reverse(all(v1));
  sort(all(v2));
  reverse(all(v2));
  sort(all(v3));
  reverse(all(v3));
  for (ll i = 0; i < x; i++)
    v4.pb(v1[i]);
  for (ll i = 0; i < y; i++)
    v4.pb(v2[i]);
  sort(all(v4));
  ll len = min(x + y, c);
  for (ll i = 0; i < len; i++) {
    if (v3[i] > v4[i])
      v4[i] = v3[i];
    else
      break;
  }
  ll sum1 = 0;
  for (ll i = 0; i < x + y; i++)
    sum1 += v4[i];
  cout << sum1;
}

int main() {
  fastio;
  randomINIT;

  // cin>>t;
  while (t--) {
    MAIN();
  }
}