Problem p02727 (C++)

Buggy submission (status: Runtime Error):
// AnkitCode99 here....
#include <bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll, ll>
#define pb push_back
// max xor btw range of two numbers..
#define max_XOR(a, b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(), v.end()
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define rep(i, a, b) for (long long int i = a; i < b; i++)
#define nrep(i, a, b) for (long long int i = a; i >= b; i--)
#define ceil(a, b) a / b + ((a % b == 0) ? 0 : 1)
using namespace std;

const ll sz = 100005;
const ll szz = 1000006;

int main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("op.txt", "w", stdout);
#endif

  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vector<pll> v;
  rep(i, 0, a) {
    ll ele;
    cin >> ele;
    v.pb({ele, 1});
  }
  rep(i, 0, b) {
    ll ele;
    cin >> ele;
    v.pb({ele, 2});
  }
  rep(i, 0, c) {
    ll ele;
    cin >> ele;
    v.pb({ele, 3});
  }

  sort(all(v));
  reverse(all(v));
  ll extra = 0, ans = 0;
  for (auto aut : v) {
    if (extra == (x + y))
      break;
    if (aut.second == 1) {
      if (x > 0) {
        ans += aut.first;
        x--;
      }
    } else if (aut.second == 2) {
      if (y > 0) {
        ans += aut.first;
        y--;
      }
    } else {
      ans += aut.first;
      extra++;
    }
  }
  cout << ans << endl;
}
// Goodbye...

Fixed submission:
// AnkitCode99 here....
#include <bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll, ll>
#define pb push_back
// max xor btw range of two numbers..
#define max_XOR(a, b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(), v.end()
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define rep(i, a, b) for (long long int i = a; i < b; i++)
#define nrep(i, a, b) for (long long int i = a; i >= b; i--)
#define ceil(a, b) a / b + ((a % b == 0) ? 0 : 1)
using namespace std;

const ll sz = 100005;
const ll szz = 1000006;

int main() {
  fast;

  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vector<pll> v;
  rep(i, 0, a) {
    ll ele;
    cin >> ele;
    v.pb({ele, 1});
  }
  rep(i, 0, b) {
    ll ele;
    cin >> ele;
    v.pb({ele, 2});
  }
  rep(i, 0, c) {
    ll ele;
    cin >> ele;
    v.pb({ele, 3});
  }

  sort(all(v));
  reverse(all(v));
  ll extra = 0, ans = 0;
  for (auto aut : v) {
    if (extra == (x + y))
      break;
    if (aut.second == 1) {
      if (x > 0) {
        ans += aut.first;
        x--;
      }
    } else if (aut.second == 2) {
      if (y > 0) {
        ans += aut.first;
        y--;
      }
    } else {
      ans += aut.first;
      extra++;
    }
  }
  cout << ans << endl;
}
// Goodbye...