prithivMLmods/Coder-Stat huggingface dataset:
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll inf = 1e18;

ll X, Y, A, B, C;
ll p[100010], q[100010], r[100010];
priority_queue<ll> pq;
ll ans;
int main() {
  cin >> X >> Y >> A >> B >> C;
  REP(i, 0, A) cin >> p[i];
  REP(i, 0, B) cin >> q[i];
  REP(i, 0, C) cin >> r[i];
  sort(p, p + A);
  sort(q, q + B);
  sort(r, r + C);
  REP(i, 0, X) { pq.push(p[A - i - 1]); }
  REP(i, 0, Y) { pq.push(q[B - i - 1]); }
  REP(i, 0, X + Y) { pq.push(r[C - i - 1]); }
  REP(i, 0, X + Y) {
    ans += pq.top();
    pq.pop();
  }
  p(ans);
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
#define RREP(i, n, N) for (ll i = (N - 1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll inf = 1e18;

ll X, Y, A, B, C;
ll p[100010], q[100010], r[100010];
priority_queue<ll> pq;
ll ans;
int main() {
  cin >> X >> Y >> A >> B >> C;
  REP(i, 0, A) cin >> p[i];
  REP(i, 0, B) cin >> q[i];
  REP(i, 0, C) cin >> r[i];
  sort(p, p + A);
  sort(q, q + B);
  sort(r, r + C);
  REP(i, 0, min(A, X)) { pq.push(p[A - i - 1]); }
  REP(i, 0, min(B, Y)) { pq.push(q[B - i - 1]); }
  REP(i, 0, min(C, X + Y)) { pq.push(r[C - i - 1]); }
  REP(i, 0, X + Y) {
    ans += pq.top();
    pq.pop();
  }
  p(ans);
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#pragma region template
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a)                                                                \
  REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a)                                                               \
  SORT(a);                                                                     \
  reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {

  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vi p(A), q(B), r(C);
  REP(i, A) { cin >> p[i]; }
  REP(i, B) { cin >> q[i]; }
  REP(i, C) { cin >> r[i]; }

  RSORT(p);
  RSORT(q);
  RSORT(r);
  vi d;
  ll ans = 0;
  REP(i, X) {
    d.push_back(p[i]);
    ans += p[i];
  }
  REP(i, Y) {
    d.push_back(q[i]);
    ans += q[i];
  }
  SORT(d);
  REP(i, C) {
    if (d[i] < r[i]) {
      ans += r[i] - d[i];
    }
  }
  OUT(ans);
}
#pragma endregion template

Fixed submission:
#pragma region template
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a)                                                                \
  REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a)                                                               \
  SORT(a);                                                                     \
  reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {

  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vi p(A), q(B), r(C);
  REP(i, A) { cin >> p[i]; }
  REP(i, B) { cin >> q[i]; }
  REP(i, C) { cin >> r[i]; }

  RSORT(p);
  RSORT(q);
  RSORT(r);
  vi d;
  ll ans = 0;
  REP(i, X) {
    d.push_back(p[i]);
    ans += p[i];
  }
  REP(i, Y) {
    d.push_back(q[i]);
    ans += q[i];
  }
  SORT(d);
  REP(i, C) {
    if (i < d.size() and d[i] < r[i]) {
      ans += r[i] - d[i];
    }
  }
  OUT(ans);
}
#pragma endregion template
Problem p02727 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
// #define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
// typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
  ll a;
  in >> a;
  o.insert(a);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);

// const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> reds(a), blues(b), whites(c);
  rep(i, a) cin >> reds[i];
  rep(i, b) cin >> blues[i];
  rep(i, c) cin >> whites[i];

  sort(reds.rbegin(), reds.rend());
  sort(blues.rbegin(), blues.rend());
  sort(whites.rbegin(), whites.rend());
  vector<ll> eats;
  rep(i, x) eats.push_back(reds[i]);
  rep(i, y) eats.push_back(blues[i]);
  for (ll l : whites)
    eats.push_back(l);
  sort(eats.rbegin(), eats.rend());
  ll ans = accumulate(eats.begin(), eats.begin() + x + y, 0ll);
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
// #define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
// typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
  ll a;
  in >> a;
  o.insert(a);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);

// const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> reds(a), blues(b), whites(c);
  rep(i, a) cin >> reds[i];
  rep(i, b) cin >> blues[i];
  rep(i, c) cin >> whites[i];

  sort(reds.rbegin(), reds.rend());
  sort(blues.rbegin(), blues.rend());
  sort(whites.rbegin(), whites.rend());
  vector<ll> eats;
  rep(i, x) eats.push_back(reds[i]);
  rep(i, y) eats.push_back(blues[i]);
  for (ll l : whites)
    eats.push_back(l);
  sort(eats.rbegin(), eats.rend());
  ll ans = accumulate(eats.begin(), eats.begin() + x + y, 0ll);
  cout << ans << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a);
  rep(i, a) { cin >> p[i]; }
  sort(all(p));
  reverse(all(p));

  vector<ll> q(a);
  rep(i, b) { cin >> q[i]; }
  sort(all(q));
  reverse(all(q));

  priority_queue<ll> r;
  rep(i, c) {
    ll d;
    cin >> d;
    r.push(d);
  }
  rep(i, x) { r.push(p[i]); }
  rep(i, y) { r.push(q[i]); }

  ll ans = 0;
  rep(i, x + y) {
    ll tmp = r.top();
    r.pop();
    ans += tmp;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a);
  rep(i, a) { cin >> p[i]; }
  sort(all(p));
  reverse(all(p));

  vector<ll> q(b);
  rep(i, b) { cin >> q[i]; }
  sort(all(q));
  reverse(all(q));

  priority_queue<ll> r;
  rep(i, c) {
    ll d;
    cin >> d;
    r.push(d);
  }
  rep(i, x) { r.push(p[i]); }
  rep(i, y) { r.push(q[i]); }

  ll ans = 0;
  rep(i, x + y) {
    ll tmp = r.top();
    r.pop();
    ans += tmp;
  }
  cout << ans << endl;

  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define nl "\n"
#define fat 1000000007

int main() {
  boost int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vi p(a), q(b), r(c);
  loop(z, p) cin >> z;
  loop(z, q) cin >> z;
  loop(z, r) cin >> z;

  sort(p.B, p.E, greater<int>());
  sort(q.B, q.E, greater<int>());
  sort(r.B, r.E, greater<int>());

  vi tot;
  for (int i = 0; i < x; i++)
    tot.pb(p[i]);
  for (int i = 0; i < y; i++)
    tot.pb(q[i]);

  sort(tot.B, tot.E);

  for (int i = 0; i < c && tot.size(); i++) {
    if (tot[i] < r[i])
      tot[i] = r[i];
  }

  cout << accumulate(tot.B, tot.E, 0LL) << nl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define nl "\n"
#define fat 1000000007

int main() {
  boost int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vi p(a), q(b), r(c);
  loop(z, p) cin >> z;
  loop(z, q) cin >> z;
  loop(z, r) cin >> z;

  sort(p.B, p.E, greater<int>());
  sort(q.B, q.E, greater<int>());
  sort(r.B, r.E, greater<int>());

  vi tot;
  for (int i = 0; i < x; i++)
    tot.pb(p[i]);
  for (int i = 0; i < y; i++)
    tot.pb(q[i]);

  sort(tot.B, tot.E);

  for (int i = 0; i < c && i < tot.size(); i++) {
    if (tot[i] < r[i])
      tot[i] = r[i];
  }

  cout << accumulate(tot.B, tot.E, 0LL) << nl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;

signed main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> P(A);
  for (int i = 0; i < A; i++)
    cin >> P.at(i);
  vector<int> Q(B);
  for (int i = 0; i < B; i++)
    cin >> Q.at(i);
  vector<int> R(A);
  for (int i = 0; i < C; i++)
    cin >> R.at(i);
  sort(P.rbegin(), P.rend());
  sort(Q.rbegin(), Q.rend());

  for (int i = 0; i < X; i++)
    R.push_back(P.at(i));
  for (int i = 0; i < Y; i++)
    R.push_back(Q.at(i));
  sort(R.rbegin(), R.rend());
  int ans = 0;
  for (int i = 0; i < X + Y; i++)
    ans += R.at(i);
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;

signed main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> P(A);
  for (int i = 0; i < A; i++)
    cin >> P.at(i);
  vector<int> Q(B);
  for (int i = 0; i < B; i++)
    cin >> Q.at(i);
  vector<int> R(C);
  for (int i = 0; i < C; i++)
    cin >> R.at(i);
  sort(P.rbegin(), P.rend());
  sort(Q.rbegin(), Q.rend());

  for (int i = 0; i < X; i++)
    R.push_back(P.at(i));
  for (int i = 0; i < Y; i++)
    R.push_back(Q.at(i));
  sort(R.rbegin(), R.rend());
  int ans = 0;
  for (int i = 0; i < X + Y; i++)
    ans += R.at(i);
  cout << ans << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int x, y, a, b, c, i;
  vector<ll> p, q, r;

  cin >> x >> y >> a >> b >> c;
  p.resize(a);
  q.resize(b);
  r.resize(c);

  for (i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (i = 0; i < c; i++) {
    cin >> r[i];
  }

  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());

  vector<ll> s;
  s.resize(x + y + c);

  int j = 0;
  for (i = a - x; i < a; i++) {
    s[j] = p[i];
    j++;
  }
  for (i = b - x; i < b; i++) {
    s[j] = q[i];
    j++;
  }
  for (i = 0; i < c; i++) {
    s[j] = r[i];
    j++;
  }

  sort(s.begin(), s.end());

  ll sum = 0;
  for (i = c; i < x + y + c; i++) {
    sum += s[i];
  }

  cout << sum << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int x, y, a, b, c, i;
  vector<ll> p, q, r;

  cin >> x >> y >> a >> b >> c;
  p.resize(a);
  q.resize(b);
  r.resize(c);

  for (i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (i = 0; i < c; i++) {
    cin >> r[i];
  }

  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());

  vector<ll> s;
  s.resize(x + y + c);

  int j = 0;
  for (i = a - x; i < a; i++) {
    s[j] = p[i];
    j++;
  }
  for (i = b - y; i < b; i++) {
    s[j] = q[i];
    j++;
  }
  for (i = 0; i < c; i++) {
    s[j] = r[i];
    j++;
  }

  sort(s.begin(), s.end());

  ll sum = 0;
  for (i = c; i < x + y + c; i++) {
    sum += s[i];
  }

  cout << sum << endl;

  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define inf 1e18

void solve() {
  int r, g, a, b, c;
  cin >> r >> g >> a >> b >> c;
  ll arr1[a], arr2[b], arr3[c];
  f(i, a) cin >> arr1[i];
  f(i, b) cin >> arr2[i];
  f(i, c) cin >> arr3[i];
  sort(arr1, arr1 + a);
  sort(arr2, arr2 + b);
  sort(arr3, arr3 + c);
  ll ans = 0;
  vector<ll> v;
  int cnt = 0;
  for (int i = a - 1; i >= 0; i--) {
    cnt++;
    ans += arr1[i];
    v.pb(arr1[i]);
    if (cnt == r)
      break;
  }
  cnt = 0;
  for (int i = b - 1; i >= 0; i--) {
    cnt++;
    ans += arr2[i];
    v.pb(arr2[i]);
    if (cnt == g)
      break;
  }
  sort(all(v));
  int j = 0;
  for (int i = c - 1; i >= 0; i--) {
    if (arr3[i] >= v[j]) {
      ans += arr3[i] - v[j];
      j++;
    } else
      break;
  }
  cout << ans << endl;
}

int main() {
#ifdef JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif
  boost;
  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++)
    solve();
  return 0;
}

Fixed submission:
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define inf 1e18

void solve() {
  int r, g, a, b, c;
  cin >> r >> g >> a >> b >> c;
  ll arr1[a], arr2[b], arr3[c];
  f(i, a) cin >> arr1[i];
  f(i, b) cin >> arr2[i];
  f(i, c) cin >> arr3[i];
  sort(arr1, arr1 + a);
  sort(arr2, arr2 + b);
  sort(arr3, arr3 + c);
  ll ans = 0;
  vector<ll> v;
  int cnt = 0;
  for (int i = a - 1; i >= 0; i--) {
    cnt++;
    ans += arr1[i];
    v.pb(arr1[i]);
    if (cnt == r)
      break;
  }
  cnt = 0;
  for (int i = b - 1; i >= 0; i--) {
    cnt++;
    ans += arr2[i];
    v.pb(arr2[i]);
    if (cnt == g)
      break;
  }
  sort(all(v));
  int j = 0;
  for (int i = c - 1; i >= 0; i--) {
    if (j == v.size())
      break;
    if (arr3[i] >= v[j]) {
      ans += arr3[i] - v[j];
      j++;
    } else
      break;
  }
  cout << ans << endl;
}

int main() {
#ifdef JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif
  boost;
  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++)
    solve();
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C; // red,green,r,g,rg
  vector<ll> P(A), Q(B), R(C);
  rep(i, A) cin >> P.at(i);
  rep(i, B) cin >> Q.at(i);
  rep(i, C) cin >> R.at(i);
  sort(begin(P), end(P));
  sort(begin(Q), end(Q));
  sort(begin(R), end(R));
  reverse(begin(R), end(R));
  queue<ll> queP, queQ;
  rep(i, X) queP.push(P.at(i - X + A));
  rep(i, Y) queQ.push(Q.at(i - Y + B));
  ll res = 0;
  rep(i, C) {
    ll p = queP.front();
    ll q = queQ.front();
    ll r = R.at(i);
    if (p < q) {
      if (r >= p) {
        res += r;
        queP.pop();
      } else
        break;
    } else {
      // p>=q
      if (r >= q) {
        res += r;
        queQ.pop();
      } else
        break;
    }
  }
  while (!queP.empty()) {
    res += queP.front();
    queP.pop();
  }
  while (!queQ.empty()) {
    res += queQ.front();
    queQ.pop();
  }
  cout << res << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C; // red,green,r,g,rg
  vector<ll> P(A), Q(B), R(C);
  rep(i, A) cin >> P.at(i);
  rep(i, B) cin >> Q.at(i);
  rep(i, C) cin >> R.at(i);
  sort(begin(P), end(P));
  sort(begin(Q), end(Q));
  sort(begin(R), end(R));
  reverse(begin(R), end(R));
  queue<ll> queP, queQ;
  rep(i, X) queP.push(P.at(i - X + A));
  rep(i, Y) queQ.push(Q.at(i - Y + B));
  ll res = 0;
  rep(i, C) {
    ll p;
    ll q;
    if (queP.empty())
      p = MOD;
    else
      p = queP.front();
    if (queQ.empty())
      q = MOD;
    else
      q = queQ.front();
    ll r = R.at(i);
    if (p < q) {
      if (r >= p) {
        res += r;
        queP.pop();
      } else
        break;
    } else {
      // p>=q
      if (r >= q) {
        res += r;
        queQ.pop();
      } else
        break;
    }
  }
  while (!queP.empty()) {
    res += queP.front();
    queP.pop();
  }
  while (!queQ.empty()) {
    res += queQ.front();
    queQ.pop();
  }
  cout << res << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> P;
#define vrep(v, n)                                                             \
  for (int i = 0; i < n; i++) {                                                \
    cin >> v.at(i);                                                            \
  } // 配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back

const int mod = 1000000007;
const int inf = 1e9;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  rep(i, 0, a) { cin >> p[i]; }
  rep(i, 0, b) { cin >> q[i]; }
  rep(i, 0, c) { cin >> r[i]; }
  sort(p.begin(), p.end(), greater<int>());
  sort(q.begin(), q.end(), greater<int>());
  sort(r.begin(), r.end(), greater<int>());
  int sum_x = 0, sum_y = 0;
  vector<ll> tmp;
  rep(i, 0, x) { tmp.pb(p[i]); }
  rep(i, 0, y) { tmp.pb(q[i]); }
  sort(tmp.begin(), tmp.end());
  for (auto &e : tmp) {
    if (e < r[0]) {
      e = r[0];
      r.erase(r.begin());
    }
  }
  ll sum = accumulate(tmp.begin(), tmp.end(), 0);
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> P;
#define vrep(v, n)                                                             \
  for (int i = 0; i < n; i++) {                                                \
    cin >> v.at(i);                                                            \
  } // 配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back

const int mod = 1000000007;
const int inf = 1e9;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  rep(i, 0, a) { cin >> p[i]; }
  rep(i, 0, b) { cin >> q[i]; }
  rep(i, 0, c) { cin >> r[i]; }
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  vi d;
  rep(i, 0, x) d.pb(p[i]);
  rep(i, 0, y) d.pb(q[i]);
  rep(i, 0, c) d.pb(r[i]);
  sort(d.rbegin(), d.rend());
  ll ans = 0;
  rep(i, 0, x + y) ans += d[i];
  cout << ans << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T> void print(const T &v);

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  for (int i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> r[i];
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  vector<ll> picks;
  for (int i = 0; i < x; i++) {
    picks.push_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    picks.push_back(q[i]);
  }
  sort(picks.begin(), picks.end());
  for (int i = 0; i < c; i++) {
    picks[i] = max(picks[i], r[i]);
  }
  ll ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += picks[i];
  }
  cout << ans << endl;
  return 0;
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ' ';
    cout << v[i];
  }
  cout << endl;
};

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T> void print(const T &v);

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  for (int i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> r[i];
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  vector<ll> picks;
  for (int i = 0; i < x; i++) {
    picks.push_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    picks.push_back(q[i]);
  }
  sort(picks.begin(), picks.end());
  for (int i = 0; i < c && i < x + y; i++) {
    picks[i] = max(picks[i], r[i]);
  }
  ll ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += picks[i];
  }
  cout << ans << endl;
  return 0;
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ' ';
    cout << v[i];
  }
  cout << endl;
};
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define dforsn(i, s, n) for (int i = int(n - 1); i >= int(s); i--)
#define forsn(i, s, n) for (int i = int(s); i < int(n); i++)
#define dforn(i, n) for (int i = int(n - 1); i >= 0; i--)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(), a.end()
#define si(a) int((a).size())
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);

  int x, y, ca, cb, cc;
  cin >> x >> y >> ca >> cb >> cc;
  vi a(ca), b(cb), c(cb);
  forn(i, ca) cin >> a[i];
  forn(i, cb) cin >> b[i];
  forn(i, cc) cin >> c[i];

  sort(all(a), greater<int>());
  sort(all(b), greater<int>());
  sort(all(c), greater<int>());

  priority_queue<int> q;
  forn(i, x) q.push(a[i]);
  forn(i, y) q.push(b[i]);
  forn(i, cc) q.push(c[i]);

  ll ans = 0;
  int t = x + y;
  forn(i, t) ans += q.top(), q.pop();
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define dforsn(i, s, n) for (int i = int(n - 1); i >= int(s); i--)
#define forsn(i, s, n) for (int i = int(s); i < int(n); i++)
#define dforn(i, n) for (int i = int(n - 1); i >= 0; i--)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(), a.end()
#define si(a) int((a).size())
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);

  int x, y, ca, cb, cc;
  cin >> x >> y >> ca >> cb >> cc;
  vi a(ca), b(cb), c(cc);
  forn(i, ca) cin >> a[i];
  forn(i, cb) cin >> b[i];
  forn(i, cc) cin >> c[i];

  sort(all(a), greater<int>());
  sort(all(b), greater<int>());
  sort(all(c), greater<int>());

  priority_queue<int> q;
  forn(i, x) q.push(a[i]);
  forn(i, y) q.push(b[i]);
  forn(i, cc) q.push(c[i]);

  ll ans = 0;
  int t = x + y;
  forn(i, t) ans += q.top(), q.pop();
  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

int main() {
  long X, Y, A, B, C;
  std::cin >> X >> Y >> A >> B >> C;
  std::vector<long> p, q, r;
  long temp;
  for (long i = 0; i < A; i++) {
    std::cin >> temp;
    p.push_back(temp);
  }
  for (long i = 0; i < B; i++) {
    std::cin >> temp;
    q.push_back(temp);
  }
  for (long i = 0; i < C; i++) {
    std::cin >> temp;
    r.push_back(temp);
  }
  std::sort(p.begin(), p.end());
  std::sort(q.begin(), q.end());
  std::sort(r.begin(), r.end());

  std::vector<long> result;
  for (long i = 0; i < X; i++) {
    result.push_back(p[A - 1 - i]);
  }
  for (long i = 0; i < Y; i++) {
    result.push_back(q[B - 1 - i]);
  }

  std::sort(result.begin(), result.end());

  long kouho = 0;
  long result2 = 0;
  for (long i = 0; i < X + Y - C; i++) {
    result2 += result[X + Y - 1 - i];
  }

  for (long i = 0; i < C; i++) {
    if (result[i] < r[C - 1 - kouho]) {
      result2 += r[C - 1 - kouho];
      kouho++;
    } else {
      result2 += result[i];
    }
  }
  std::cout << result2 << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

int main() {
  long X, Y, A, B, C;
  std::cin >> X >> Y >> A >> B >> C;
  std::vector<long> p, q, r;
  long temp;
  for (long i = 0; i < A; i++) {
    std::cin >> temp;
    p.push_back(temp);
  }
  for (long i = 0; i < B; i++) {
    std::cin >> temp;
    q.push_back(temp);
  }
  for (long i = 0; i < C; i++) {
    std::cin >> temp;
    r.push_back(temp);
  }
  std::sort(p.begin(), p.end());
  std::sort(q.begin(), q.end());
  std::sort(r.begin(), r.end());

  std::vector<long> result;
  for (long i = 0; i < X; i++) {
    result.push_back(p[A - 1 - i]);
  }
  for (long i = 0; i < Y; i++) {
    result.push_back(q[B - 1 - i]);
  }

  std::sort(result.begin(), result.end());

  long kouho = 0;
  long result2 = 0;
  for (long i = 0; i < X + Y - C; i++) {
    result2 += result[X + Y - 1 - i];
  }

  for (long i = 0; i < std::min(C, X + Y); i++) {
    if (result[i] < r[C - 1 - kouho]) {
      result2 += r[C - 1 - kouho];
      kouho++;
    } else {
      result2 += result[i];
    }
  }
  std::cout << result2 << std::endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
//============================================================================
// Name        : e.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  for (int i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> r[i];
  }
  vector<ll> ab;
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());
  for (int i = 0; i < x; i++) {
    ab.push_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    ab.push_back(q[i]);
  }
  sort(ab.begin(), ab.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  for (int i = 0; i < c; i++) {
    if (ab[i] < r[i]) {
      ab[i] = r[i];
    }
  }
  ll ans = 0;
  for (int i = 0; i < ab.size(); i++) {
    ans += ab[i];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
//============================================================================
// Name        : e.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  for (int i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> r[i];
  }
  vector<ll> ab;
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());
  for (int i = 0; i < x; i++) {
    ab.push_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    ab.push_back(q[i]);
  }
  sort(ab.begin(), ab.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  for (int i = 0; i < c; i++) {
    if (ab[i] < r[i]) {
      ab[i] = r[i];
    }
    if (i == ab.size() - 1)
      break;
  }
  ll ans = 0;
  for (int i = 0; i < ab.size(); i++) {
    ans += ab[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  for (int i = 0; i < a; ++i)
    cin >> p.at(i);
  for (int i = 0; i < b; ++i)
    cin >> q.at(i);
  for (int i = 0; i < c; ++i)
    cin >> r.at(i);
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  priority_queue<int, vector<int>, greater<int>> s, t;
  for (int i = 0; i < x; ++i) {
    s.push(p.at(a - i - 1));
  }
  for (int i = 0; i < y; ++i) {
    t.push(q.at(a - i - 1));
  }
  for (auto ri : r) {
    int si = s.top();
    int ti = t.top();
    if (si < ti) {
      if (ri > si) {
        s.pop();
        s.push(ri);
      }
    } else {
      if (ri > ti) {
        t.pop();
        t.push(ri);
      }
    }
  }
  long long ans = 0;
  while (!s.empty()) {
    ans += s.top();
    s.pop();
  }
  while (!t.empty()) {
    ans += t.top();
    t.pop();
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  for (int i = 0; i < a; ++i)
    cin >> p.at(i);
  for (int i = 0; i < b; ++i)
    cin >> q.at(i);
  for (int i = 0; i < c; ++i)
    cin >> r.at(i);
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  priority_queue<int, vector<int>, greater<int>> s, t;
  for (int i = 0; i < x; ++i) {
    s.push(p.at(a - i - 1));
  }
  for (int i = 0; i < y; ++i) {
    t.push(q.at(b - i - 1));
  }
  for (auto ri : r) {
    int si = s.top();
    int ti = t.top();
    if (si < ti) {
      if (ri > si) {
        s.pop();
        s.push(ri);
      }
    } else {
      if (ri > ti) {
        t.pop();
        t.push(ri);
      }
    }
  }
  long long ans = 0;
  while (!s.empty()) {
    ans += s.top();
    s.pop();
  }
  while (!t.empty()) {
    ans += t.top();
    t.pop();
  }

  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;

int X, Y, A, B, C;
int red[100005], green[100005], color[100005];
vector<int> best;
long long ans;

int32_t main() {
  scanf("%lld %lld %lld %lld %lld", &X, &Y, &A, &B, &C);
  for (int i = 0; i < A; i++) {
    scanf("%lld", &red[i]);
  }
  sort(red, red + A, greater<int>());
  for (int i = 0; i < B; i++) {
    scanf("%lld", &green[i]);
  }
  sort(green, green + B, greater<int>());
  for (int i = 0; i < C; i++) {
    scanf("%lld", &color[i]);
  }
  sort(color, color + C, greater<int>());
  for (int i = 0; i < max(X, Y); i++) {
    if (i < X) {
      best.push_back(red[i]);
      ans += red[i];
    }
    if (i < Y) {
      best.push_back(green[i]);
      ans += green[i];
    }
  }
  sort(best.begin(), best.end());
  for (int i = 0; i < C; i++) {
    if (color[i] > best[i]) {
      ans += color[i] - best[i];
    }
  }
  cout << ans << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;

int X, Y, A, B, C;
int red[100005], green[100005], color[100005];
vector<int> best;
long long ans;

int32_t main() {
  scanf("%lld %lld %lld %lld %lld", &X, &Y, &A, &B, &C);
  for (int i = 0; i < A; i++) {
    scanf("%lld", &red[i]);
  }
  sort(red, red + A, greater<int>());
  for (int i = 0; i < B; i++) {
    scanf("%lld", &green[i]);
  }
  sort(green, green + B, greater<int>());
  for (int i = 0; i < C; i++) {
    scanf("%lld", &color[i]);
  }
  sort(color, color + C, greater<int>());
  for (int i = 0; i < max(X, Y); i++) {
    if (i < X) {
      best.push_back(red[i]);
      ans += red[i];
    }
    if (i < Y) {
      best.push_back(green[i]);
      ans += green[i];
    }
  }
  sort(best.begin(), best.end());
  for (int i = 0; i < min(C, X + Y) && color[i] > best[i]; i++) {
    ans += color[i] - best[i];
  }
  cout << ans << "\n";
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
int x, n, y, a, b, c, cnt[maxn];
struct node {
  int v, c;
  bool operator<(const node &rhs) const { return v > rhs.v; }
} p[maxn];
int main() {
  scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
  for (int i = 1; i <= a; i++) {
    scanf("%d", &p[i].v);
    p[i].c = 1;
  }
  for (int i = 1; i <= b; i++) {
    scanf("%d", &p[a + i].v);
    p[a + i].c = 2;
  }
  for (int i = 1; i <= c; i++) {
    scanf("%d", &p[a + b + i].v);
    p[a + b + i].c = 0;
  }
  sort(p + 1, p + a + b + c + 1);
  int cx = 0, cy = 0, tot = 0;
  ll ans = 0;
  for (int i = 1; i <= a + b + c && tot < x + y; i++) {
    if (p[i].c == 1 && cx < x) {
      ans += p[i].v;
      cx++;
      tot++;
    } else if (p[i].c == 2 && cy < y) {
      ans += p[i].v;
      cy++;
      tot++;
    } else if (p[i].c == 0) {
      ans += p[i].v;
      tot++;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
typedef long long ll;
int x, n, y, a, b, c, cnt[maxn];
struct node {
  int v, c;
  bool operator<(const node &rhs) const { return v > rhs.v; }
} p[maxn];
int main() {
  scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
  for (int i = 1; i <= a; i++) {
    scanf("%d", &p[i].v);
    p[i].c = 1;
  }
  for (int i = 1; i <= b; i++) {
    scanf("%d", &p[a + i].v);
    p[a + i].c = 2;
  }
  for (int i = 1; i <= c; i++) {
    scanf("%d", &p[a + b + i].v);
    p[a + b + i].c = 0;
  }
  sort(p + 1, p + a + b + c + 1);
  int cx = 0, cy = 0, tot = 0;
  ll ans = 0;
  for (int i = 1; i <= a + b + c && tot < x + y; i++) {
    if (p[i].c == 1 && cx < x) {
      ans += p[i].v;
      cx++;
      tot++;
    } else if (p[i].c == 2 && cy < y) {
      ans += p[i].v;
      cy++;
      tot++;
    } else if (p[i].c == 0) {
      ans += p[i].v;
      tot++;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  int x, y;
  int abc[3];
  cin >> x >> y;
  for (int i = 0; i < 3; i++) {
    cin >> abc[i];
  }
  int pqr[3][100000];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < abc[i]; j++) {
      cin >> pqr[i][j];
    }
  }
  for (int i = 0; i < 3; i++) {
    sort(pqr[i], pqr[i] + abc[i]);
    reverse(pqr[i], pqr[i] + abc[i]);
  }
  vector<int> tmp;
  for (int i = 0; i < x; i++) {
    tmp.push_back(pqr[0][i]);
  }
  for (int i = 0; i < y; i++) {
    tmp.push_back(pqr[1][i]);
  }
  for (int i = 0; i < x + y; i++) {
    tmp.push_back(pqr[2][i]);
  }
  sort(tmp.begin(), tmp.end());
  reverse(tmp.begin(), tmp.end());
  long long int ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += tmp[i];
  }
  cout << ans << endl;
}

Fixed submission:
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  int x, y;
  int abc[3];
  cin >> x >> y;
  for (int i = 0; i < 3; i++) {
    cin >> abc[i];
  }
  int pqr[3][100000];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < abc[i]; j++) {
      cin >> pqr[i][j];
    }
  }
  for (int i = 0; i < 3; i++) {
    sort(pqr[i], pqr[i] + abc[i]);
    reverse(pqr[i], pqr[i] + abc[i]);
  }
  vector<int> tmp;
  for (int i = 0; i < x; i++) {
    tmp.push_back(pqr[0][i]);
  }
  for (int i = 0; i < y; i++) {
    tmp.push_back(pqr[1][i]);
  }
  for (int i = 0; i < min(x + y, abc[2]); i++) {
    tmp.push_back(pqr[2][i]);
  }
  sort(tmp.begin(), tmp.end());
  reverse(tmp.begin(), tmp.end());
  long long int ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += tmp[i];
  }
  cout << ans << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
int red[maxn], green[maxn], white[maxn];
priority_queue<int, vector<int>, greater<int>> r, g, w;
bool cmp(int a, int b) { return a > b; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  for (int i = 1; i <= a; i++) {
    cin >> red[i];
  }
  for (int i = 1; i <= b; i++) {
    cin >> green[i];
  }
  for (int i = 1; i <= c; i++) {
    cin >> white[i];
  }
  sort(red + 1, red + 1 + a, cmp);
  sort(green + 1, green + 1 + b, cmp);
  sort(white + 1, white + 1 + c, cmp);

  for (int i = 1; i <= x; i++)
    r.push(red[i]);
  for (int i = 1; i <= y; i++)
    g.push(green[i]);
  int cnt;
  for (int i = c; i >= 1; i--) {
    cnt = white[i];
    if (r.top() > g.top()) {
      g.push(cnt);
      g.pop();
    } else {
      r.push(cnt);
      r.pop();
    }
  }
  long long ans = 0;
  while (!r.empty()) {
    ans += r.top();
    r.pop();
  }
  while (!g.empty()) {
    ans += g.top();
    g.pop();
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int red[maxn], green[maxn], white[maxn];
priority_queue<int, vector<int>, greater<int>> r, g, w;
bool cmp(int a, int b) { return a > b; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  for (int i = 1; i <= a; i++) {
    cin >> red[i];
  }
  for (int i = 1; i <= b; i++) {
    cin >> green[i];
  }
  for (int i = 1; i <= c; i++) {
    cin >> white[i];
  }
  sort(red + 1, red + 1 + a, cmp);
  sort(green + 1, green + 1 + b, cmp);
  sort(white + 1, white + 1 + c, cmp);

  for (int i = 1; i <= x; i++)
    r.push(red[i]);
  for (int i = 1; i <= y; i++)
    g.push(green[i]);
  int cnt;
  for (int i = c; i >= 1; i--) {
    cnt = white[i];
    if (r.top() > g.top()) {
      g.push(cnt);
      g.pop();
    } else {
      r.push(cnt);
      r.pop();
    }
  }
  long long ans = 0;
  while (!r.empty()) {
    ans += r.top();
    r.pop();
  }
  while (!g.empty()) {
    ans += g.top();
    g.pop();
  }
  cout << ans << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a);
  for (int i = 0; i < a; i++)
    cin >> p[i];
  vector<int> q(b);
  for (int i = 0; i < b; i++)
    cin >> q[i];
  vector<int> r(c);
  for (int i = 0; i < c; i++)
    cin >> r[i];
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());

  ll sum = 0;
  vector<int> s;
  for (int i = a - x; i < a; i++) {
    sum += p[i];
    s.push_back(p[i]);
  }
  for (int i = b - y; i < b; i++) {
    sum += q[i];
    s.push_back(q[i]);
  }
  sort(s.begin(), s.end());

  int i = 0;

  while (i < c || i < x + y) {
    sum += max(s[i], r[i]) - s[i];
    i++;
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a);
  for (int i = 0; i < a; i++)
    cin >> p[i];
  vector<int> q(b);
  for (int i = 0; i < b; i++)
    cin >> q[i];
  vector<int> r(c);
  for (int i = 0; i < c; i++)
    cin >> r[i];
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());

  ll sum = 0;
  vector<int> s;
  for (int i = a - x; i < a; i++) {
    sum += p[i];
    s.push_back(p[i]);
  }
  for (int i = b - y; i < b; i++) {
    sum += q[i];
    s.push_back(q[i]);
  }
  sort(s.begin(), s.end());

  int i = 0;

  while (i < c && i < x + y) {
    sum += max(s[i], r[i]) - s[i];
    i++;
  }
  cout << sum << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define CFS                                                                    \
  cin.tie(nullptr);                                                            \
  ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
const int IINF = 1 << 30;
const long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
// const int MOD = 998244353;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<long> va(a);
  vector<long> vb(b);
  for (size_t i = 0; i < a; i++) {
    cin >> va[i];
  }
  for (size_t i = 0; i < a; i++) {
    cin >> vb[i];
  }
  sort(va.rbegin(), va.rend());
  sort(vb.rbegin(), vb.rend());
  priority_queue<long> pq;
  for (size_t i = 0; i < x; i++) {
    pq.push(va[i]);
  }
  for (size_t i = 0; i < y; i++) {
    pq.push(vb[i]);
  }
  for (size_t i = 0; i < c; i++) {
    int t;
    cin >> t;
    pq.push(t);
  }

  long ans = 0;
  for (size_t i = 0; i < x + y; i++) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
#define CFS                                                                    \
  cin.tie(nullptr);                                                            \
  ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
const int IINF = 1 << 30;
const long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
// const int MOD = 998244353;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<long> va(a);
  vector<long> vb(b);
  for (size_t i = 0; i < a; i++) {
    cin >> va[i];
  }
  for (size_t i = 0; i < b; i++) {
    cin >> vb[i];
  }
  sort(va.rbegin(), va.rend());
  sort(vb.rbegin(), vb.rend());
  priority_queue<long> pq;
  for (size_t i = 0; i < x; i++) {
    pq.push(va[i]);
  }
  for (size_t i = 0; i < y; i++) {
    pq.push(vb[i]);
  }
  for (size_t i = 0; i < c; i++) {
    int t;
    cin >> t;
    pq.push(t);
  }

  long ans = 0;
  for (size_t i = 0; i < x + y; i++) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << "\n";
}