Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
// #include"testlib.h"
#define endl "\n"
#define all(v) v.begin(), v.end()
#define allr(s) s.rbegin(), s.rend()
#define RT(s) return cout << s, 0
#define watch(x) cout << (#x) << " = " << x << endl
#define sz(s) (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#else
  // freopen("street.in", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}

int main() {
  // file();
  fast();
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> v1(a), v2(b), v3(c + 1);
  for (auto &it : v1)
    cin >> it;
  for (auto &it : v2)
    cin >> it;
  for (int i = 1; i <= c; i++)
    cin >> v3[i];

  sort(v3.begin() + 1, v3.end());
  reverse(v3.begin() + 1, v3.end());
  for (int i = 1; i <= c; i++)
    v3[i] += v3[i - 1];

  vector<ll> All(1);
  sort(allr(v1)), sort(allr(v2));
  for (int i = 0; i < x; i++)
    All.push_back(v1[i]);
  for (int i = 0; i < y; i++)
    All.push_back(v2[i]);
  sort(All.begin() + 1, All.end());
  for (int i = 1; i < sz(All); i++)
    All[i] += All[i - 1];

  ll ans = All.back();
  for (int i = 1; i <= c; i++) {
    if (v3[i] + All.back() - All[i] > ans)
      ans = v3[i] + All.back() - All[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
// #include"testlib.h"
#define endl "\n"
#define all(v) v.begin(), v.end()
#define allr(s) s.rbegin(), s.rend()
#define RT(s) return cout << s, 0
#define watch(x) cout << (#x) << " = " << x << endl
#define sz(s) (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#else
  // freopen("street.in", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}

int main() {
  // file();
  fast();
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> v1(a), v2(b), v3(c + 1);
  for (auto &it : v1)
    cin >> it;
  for (auto &it : v2)
    cin >> it;
  for (int i = 1; i <= c; i++)
    cin >> v3[i];

  sort(v3.begin() + 1, v3.end());
  reverse(v3.begin() + 1, v3.end());
  for (int i = 1; i <= c; i++)
    v3[i] += v3[i - 1];

  vector<ll> All(1);
  sort(allr(v1)), sort(allr(v2));
  for (int i = 0; i < x; i++)
    All.push_back(v1[i]);
  for (int i = 0; i < y; i++)
    All.push_back(v2[i]);
  sort(All.begin() + 1, All.end());
  for (int i = 1; i < sz(All); i++)
    All[i] += All[i - 1];

  ll ans = All.back();
  for (int i = 1; i < min(sz(v3), sz(All)); i++) {
    if (v3[i] + All.back() - All[i] > ans)
      ans = v3[i] + All.back() - All[i];
  }
  cout << ans << endl;
  return 0;
}