Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

// #define int long long

#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
// const ll mod = 1e9 + 9;
const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed;
  cout.precision(15);
  solve();
  return 0;
}

const int N = 2e5 + 7;

ll cnt[N];

void solve() {
  fill(cnt, cnt + N, -inf);
  int x, y;
  cin >> x >> y;
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> a1(a), b1(b), c1(c);
  for (int &i : a1)
    cin >> i;
  for (int &i : b1)
    cin >> i;
  for (int &i : c1)
    cin >> i;
  vector<pair<int, int>> kek;
  for (int i : a1)
    kek.push_back({i, 0});
  for (int i : b1)
    kek.push_back({i, 1});
  sort(rall(kek));
  int c0 = x;
  int cc = y;
  int cn = 0;
  ll su = 0;
  cnt[0] = 0;
  for (auto u : kek) {
    if (u.second == 0) {
      if (c0) {
        c0--;
        su += u.first;
        cn++;
      }
    } else {
      if (cc) {
        cc--;
        su += u.first;
        cn++;
      }
    }
    cnt[cn] = su;
  }
  ll ans = cnt[x + y];
  sort(rall(c1));
  su = 0;
  for (int i = 0; i < c; i++) {
    ;
    su += c1[i];
    ans = max(ans, cnt[x + y - i - 1] + su);
  }
  cout << ans << endl;
  return;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

// #define int long long

#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
// const ll mod = 1e9 + 9;
const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed;
  cout.precision(15);
  solve();
  return 0;
}

const int N = 2e5 + 7;

ll cnt[N];

void solve() {
  fill(cnt, cnt + N, -inf);
  int x, y;
  cin >> x >> y;
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> a1(a), b1(b), c1(c);
  for (int &i : a1)
    cin >> i;
  for (int &i : b1)
    cin >> i;
  for (int &i : c1)
    cin >> i;
  vector<pair<int, int>> kek;
  for (int i : a1)
    kek.push_back({i, 0});
  for (int i : b1)
    kek.push_back({i, 1});
  sort(rall(kek));
  int c0 = x;
  int cc = y;
  int cn = 0;
  ll su = 0;
  cnt[0] = 0;
  for (auto u : kek) {
    if (u.second == 0) {
      if (c0) {
        c0--;
        su += u.first;
        cn++;
      }
    } else {
      if (cc) {
        cc--;
        su += u.first;
        cn++;
      }
    }
    cnt[cn] = su;
  }
  ll ans = cnt[x + y];
  sort(rall(c1));
  su = 0;
  for (int i = 0; i < c; i++) {
    ;
    if ((i + 1) > x + y)
      break;
    su += c1[i];
    ans = max(ans, cnt[x + y - i - 1] + su);
  }
  cout << ans << endl;
  return;
}