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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define PB push_back
#define MP make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 28)
#define LLINF (1LL << 60)
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
  int x, y, a, b, c, p[10000], q[10000], r[10000], rg[30000];
  cin >> x >> y >> a >> b >> 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, p + a, greater<>());
  sort(q, q + b, greater<>());
  sort(r, r + c, greater<>());
  for (int i = 0; i < x; i++)
    rg[i] = p[i];
  for (int i = 0; i < y; i++)
    rg[i + x] = q[i];
  for (int i = 0; i < c; i++)
    rg[i + x + y] = r[i];
  sort(rg, rg + x + y + c, greater<>());
  ll ans = 0;
  for (int i = 0; i < x + y; i++)
    ans += rg[i];
  cout << ans;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define PB push_back
#define MP make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 28)
#define LLINF (1LL << 60)
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
  int x, y, a, b, c, p[100000], q[100000], r[100000], rg[300000];
  cin >> x >> y >> a >> b >> 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, p + a, greater<>());
  sort(q, q + b, greater<>());
  sort(r, r + c, greater<>());
  for (int i = 0; i < x; i++)
    rg[i] = p[i];
  for (int i = 0; i < y; i++)
    rg[i + x] = q[i];
  for (int i = 0; i < c; i++)
    rg[i + x + y] = r[i];
  sort(rg, rg + x + y + c, greater<>());
  ll ans = 0;
  for (int i = 0; i < x + y; i++)
    ans += rg[i];
  cout << ans;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

int main() {
  std::size_t X, Y, A, B, C;
  std::cin >> X >> Y >> A >> B >> C;

  std::vector<std::uint64_t> ps(A);
  std::vector<std::uint64_t> qs(B);
  std::vector<std::uint64_t> rs(C);

  for (auto &p : ps) {
    std::cin >> p;
  }
  for (auto &q : qs) {
    std::cin >> q;
  }
  for (auto &r : rs) {
    std::cin >> r;
  }

  const auto gt = [](const std::uint64_t lhs,
                     const std::uint64_t rhs) noexcept -> bool {
    return lhs > rhs;
  };

  std::sort(ps.begin(), ps.end(), gt);
  std::sort(qs.begin(), qs.end(), gt);
  std::sort(rs.begin(), rs.end());

  ps.erase(ps.begin() + X, ps.end());
  qs.erase(qs.begin() + Y, qs.end());

  while (!rs.empty()) {
    std::cerr << "current status:" << std::endl;
    std::cerr << "red  : ";
    for (const auto p : ps) {
      std::cerr << p << ' ';
    }
    std::cerr << std::endl;
    std::cerr << "green: ";
    for (const auto q : qs) {
      std::cerr << q << ' ';
    }
    std::cerr << std::endl;
    std::cerr << "cless: ";
    for (const auto r : rs) {
      std::cerr << r << ' ';
    }
    std::cerr << std::endl;

    if (std::min(ps.back(), qs.back()) < rs.back()) {
      if (ps.back() < qs.back()) {
        ps.pop_back();
        ps.insert(std::lower_bound(ps.begin(), ps.end(), rs.back(), gt),
                  rs.back());
      } else // qs.back() <= ps.back()
      {
        qs.pop_back();
        qs.insert(std::lower_bound(qs.begin(), qs.end(), rs.back(), gt),
                  rs.back());
      }
      rs.pop_back();
    } else {
      break;
    }
  }

  std::size_t ans = 0;
  for (const auto &p : ps) {
    ans += p;
  }
  for (const auto &q : qs) {
    ans += q;
  }
  std::cout << ans << std::endl;

  return 0;
}


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

int main() {
  std::size_t X, Y, A, B, C;
  std::cin >> X >> Y >> A >> B >> C;

  std::vector<std::uint64_t> ps(A);
  std::vector<std::uint64_t> qs(B);
  std::vector<std::uint64_t> rs(C);

  for (auto &p : ps) {
    std::cin >> p;
  }
  for (auto &q : qs) {
    std::cin >> q;
  }
  for (auto &r : rs) {
    std::cin >> r;
  }

  const auto gt = [](const std::uint64_t lhs,
                     const std::uint64_t rhs) noexcept -> bool {
    return lhs > rhs;
  };

  std::sort(ps.begin(), ps.end(), gt);
  std::sort(qs.begin(), qs.end(), gt);
  std::sort(rs.begin(), rs.end());

  ps.erase(ps.begin() + X, ps.end());
  qs.erase(qs.begin() + Y, qs.end());

  while (!rs.empty()) {
    if (std::min(ps.back(), qs.back()) < rs.back()) {
      if (ps.back() < qs.back()) {
        ps.pop_back();
        ps.insert(std::lower_bound(ps.begin(), ps.end(), rs.back(), gt),
                  rs.back());
      } else // qs.back() <= ps.back()
      {
        qs.pop_back();
        qs.insert(std::lower_bound(qs.begin(), qs.end(), rs.back(), gt),
                  rs.back());
      }
      rs.pop_back();
    } else {
      break;
    }
  }

  std::size_t ans = 0;
  for (const auto &p : ps) {
    ans += p;
  }
  for (const auto &q : qs) {
    ans += q;
  }
  std::cout << ans << std::endl;

  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
// codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll *A, ll n) {
  for (ll K = 0; K < n; K++) {
    cin >> A[K];
  }
}
ll modInverse(ll a, ll b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(ll *a, ll n) {
  for (ll k = 0; k < n; k++) {
    cerr << a[k] << " ";
  }
  cerr << "\n";
}
#define PI 3.14159265358979323846

int main() {
  FASTIO;
  ll x, y, n, m, p;
  cin >> x >> y >> n >> m >> p;
  ll a[n];
  parseArray(a, n);
  ll b[n];
  parseArray(b, m);
  ll c[p];
  parseArray(c, p);
  sort(a, a + n);
  reverse(a, a + n);
  sort(b, b + m);
  reverse(b, b + m);
  sort(c, c + p);
  reverse(c, c + p);
  ll ans = 0;
  priority_queue<ll> pq;
  for (int k = 0; k < x; k++)
    pq.push(-a[k]), ans += a[k];
  for (int k = 0; k < y; k++)
    pq.push(-b[k]), ans += b[k];
  for (int k = 0; k < p; k++) {
    if (c[k] > -pq.top()) {
      ans -= -pq.top();
      pq.pop();
      pq.push(-c[k]);
      ans += c[k];
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
// codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll *A, ll n) {
  for (ll K = 0; K < n; K++) {
    cin >> A[K];
  }
}
ll modInverse(ll a, ll b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(ll *a, ll n) {
  for (ll k = 0; k < n; k++) {
    cerr << a[k] << " ";
  }
  cerr << "\n";
}
#define PI 3.14159265358979323846

int main() {
  FASTIO;
  ll x, y, n, m, p;
  cin >> x >> y >> n >> m >> p;
  ll a[n];
  parseArray(a, n);
  ll b[m];
  parseArray(b, m);
  ll c[p];
  parseArray(c, p);
  sort(a, a + n);
  reverse(a, a + n);
  sort(b, b + m);
  reverse(b, b + m);
  sort(c, c + p);
  reverse(c, c + p);
  ll ans = 0;
  priority_queue<ll> pq;
  for (int k = 0; k < x; k++)
    pq.push(-a[k]), ans += a[k];
  for (int k = 0; k < y; k++)
    pq.push(-b[k]), ans += b[k];
  for (int k = 0; k < p; k++) {
    if (c[k] > -pq.top()) {
      ans -= -pq.top();
      pq.pop();
      pq.push(-c[k]);
      ans += c[k];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
using namespace std;
//  Table is the complete reverse of dp

int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
  int x, y, a, b, c, z;
  priority_queue<pair<int, char>> p;
  cin >> x >> y >> a >> b >> c;
  for (int i = 0; i < a; i++) {
    cin >> z;
    p.push(pair<int, char>(z, 1));
  }
  for (int i = 0; i < b; i++) {
    cin >> z;
    p.push(pair<int, char>(z, 2));
  }
  for (int i = 0; i < c; i++) {
    cin >> z;
    p.push(pair<int, char>(z, 0));
  }
  z = 0;
  ll ans = 0;
  while (x + y > z) {
    if (!p.top().second || (p.top().second == 1 && x) ||
        (p.top().second == 2 && y)) {
      ans = ans + p.top().first;
      if (!p.top().second)
        z++;
      else if (p.top().second == 1)
        x--;
      else
        y--;
    }
    p.pop();
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
using namespace std;
//  Table is the complete reverse of dp

int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
  int x, y, a, b, c, z;
  priority_queue<pair<int, char>> p;
  cin >> x >> y >> a >> b >> c;
  for (int i = 0; i < a; i++) {
    cin >> z;
    p.push(pair<int, char>(z, 1));
  }
  for (int i = 0; i < b; i++) {
    cin >> z;
    p.push(pair<int, char>(z, 2));
  }
  for (int i = 0; i < c; i++) {
    cin >> z;
    p.push(pair<int, char>(z, 0));
  }
  z = 0;
  ll ans = 0;
  while (x + y > z) {
    if (!p.top().second || (p.top().second == 1 && x) ||
        (p.top().second == 2 && y)) {
      ans = ans + p.top().first;
      if (!p.top().second)
        z++;
      else if (p.top().second == 1)
        x--;
      else
        y--;
    }
    p.pop();
  }
  cout << ans;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int, int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9 + 7;

int p[maxn], q[maxn], r[maxn];

int sum[maxn];
int ans[maxn];

signed main() {
#ifdef ONLINE_JUDGE
#else
  freopen("data.in", "r", stdin);
#endif
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  int n = x + y;
  for (int i = 1; i <= a; i++) {
    cin >> p[i];
  }
  sort(p + 1, p + 1 + a, greater<int>());
  for (int i = 1; i <= b; i++) {
    cin >> q[i];
  }
  sort(q + 1, q + 1 + b, greater<int>());
  for (int i = 1; i <= c; i++) {
    cin >> r[i];
  }
  sort(r + 1, r + 1 + c, greater<int>());
  for (int i = 1; i <= c; i++) {
    sum[i] = sum[i - 1] + r[i];
  }
  int red = 0, green = 0, pos = 1;
  while (red < x && green < y) {
    if (p[red + 1] > q[green + 1]) {
      red++;
      ans[pos] = ans[pos - 1] + p[red];
    } else {
      green++;
      ans[pos] = ans[pos - 1] + q[green];
    }
    pos++;
  }
  while (red < x) {
    red++;
    ans[pos] = ans[pos - 1] + p[red];
    pos++;
  }
  while (green < y) {
    green++;
    ans[pos] = ans[pos - 1] + q[green];
    pos++;
  }
  int res = 0;
  for (int i = 0; i <= min(c, n); i++) {
    res = max(res, sum[i] + ans[n - i]);
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int, int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9 + 7;

int p[maxn], q[maxn], r[maxn];

int sum[maxn];
int ans[maxn];

signed main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  int n = x + y;
  for (int i = 1; i <= a; i++) {
    cin >> p[i];
  }
  sort(p + 1, p + 1 + a, greater<int>());
  for (int i = 1; i <= b; i++) {
    cin >> q[i];
  }
  sort(q + 1, q + 1 + b, greater<int>());
  for (int i = 1; i <= c; i++) {
    cin >> r[i];
  }
  sort(r + 1, r + 1 + c, greater<int>());
  for (int i = 1; i <= c; i++) {
    sum[i] = sum[i - 1] + r[i];
  }
  int red = 0, green = 0, pos = 1;
  while (red < x && green < y) {
    if (p[red + 1] > q[green + 1]) {
      red++;
      ans[pos] = ans[pos - 1] + p[red];
    } else {
      green++;
      ans[pos] = ans[pos - 1] + q[green];
    }
    pos++;
  }
  while (red < x) {
    red++;
    ans[pos] = ans[pos - 1] + p[red];
    pos++;
  }
  while (green < y) {
    green++;
    ans[pos] = ans[pos - 1] + q[green];
    pos++;
  }
  int res = 0;
  for (int i = 0; i <= min(c, n); i++) {
    res = max(res, sum[i] + ans[n - i]);
  }
  cout << res << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mod ((int)1e9 + 7)
using namespace std;
typedef pair<int, int> pi;
typedef long long int ll;

const int N = (int)2e3 + 5;

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a + 1), q(b), r(c + 1);
  for (int i = 1; i <= a; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  sort(q.begin(), q.end());
  for (int i = 1; i <= c; i++) {
    cin >> r[i];
  }
  sort(r.begin(), r.end());
  vector<ll> temp_r(c + 1);
  priority_queue<ll, vector<ll>, greater<ll>> pq;
  ll sum = 0;
  for (auto it : q) {
    pq.push(it);
    sum += it;
  }
  for (int i = 0; i <= c; i++) {
    if (i > 0) {
      pq.push(r[i]);
      sum += r[i];
    }
    while (pq.size() > y) {
      sum -= pq.top();
      pq.pop();
    }
    temp_r[i] = sum;
  }
  for (int i = 1; i <= a; i++) {
    p[i] += p[i - 1];
  }
  for (int i = 1; i <= c; i++) {
    r[i] += r[i - 1];
  }
  ll ans = 0;
  for (int i = 0; i <= x; i++) {
    ans =
        max(ans, temp_r[c - (x - i)] + r[c] - r[c - (x - i)] + p[a] - p[a - i]);
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define mod ((int)1e9 + 7)
using namespace std;
typedef pair<int, int> pi;
typedef long long int ll;

const int N = (int)2e3 + 5;

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a + 1), q(b), r(c + 1);
  for (int i = 1; i <= a; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  sort(q.begin(), q.end());
  for (int i = 1; i <= c; i++) {
    cin >> r[i];
  }
  sort(r.begin(), r.end());
  vector<ll> temp_r(c + 1);
  priority_queue<ll, vector<ll>, greater<ll>> pq;
  ll sum = 0;
  for (auto it : q) {
    pq.push(it);
    sum += it;
  }
  for (int i = 0; i <= c; i++) {
    if (i > 0) {
      pq.push(r[i]);
      sum += r[i];
    }
    while (pq.size() > y) {
      sum -= pq.top();
      pq.pop();
    }
    temp_r[i] = sum;
  }
  for (int i = 1; i <= a; i++) {
    p[i] += p[i - 1];
  }
  for (int i = 1; i <= c; i++) {
    r[i] += r[i - 1];
  }
  ll ans = 0;
  for (int i = 0; i <= x; i++) {
    if ((c - (x - i)) >= 0 && ((c - (x - i)) <= c))
      ans = max(ans,
                temp_r[c - (x - i)] + r[c] - r[c - (x - i)] + p[a] - p[a - i]);
  }
  cout << ans;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a);
  vector<ll> q(b);
  vector<ll> r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(p.begin(), p.end(), greater<>());
  sort(q.begin(), q.end(), greater<>());
  sort(r.begin(), r.end(), greater<>());
  vector<ll> s(x);
  vector<ll> t(y);
  rep(i, x) s[i] = p[i];
  rep(i, y) t[i] = q[i];
  ll ans = 0;
  rep(i, x) ans += s[i];
  rep(i, y) ans += t[i];
  vector<ll> z;
  rep(i, x) z.push_back(s[i]);
  rep(i, y) z.push_back(t[i]);
  sort(z.begin(), z.end());
  rep(i, c) {
    if (z[i] < r[i]) {
      ans -= z[i];
      ans += r[i];
    }
  }
  cout << ans << endl;
  return (0);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a);
  vector<ll> q(b);
  vector<ll> r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(p.begin(), p.end(), greater<>());
  sort(q.begin(), q.end(), greater<>());
  sort(r.begin(), r.end(), greater<>());
  vector<ll> s(x);
  vector<ll> t(y);
  rep(i, x) s[i] = p[i];
  rep(i, y) t[i] = q[i];
  ll ans = 0;
  rep(i, x) ans += s[i];
  rep(i, y) ans += t[i];
  vector<ll> z;
  rep(i, x) z.push_back(s[i]);
  rep(i, y) z.push_back(t[i]);
  sort(z.begin(), z.end());
  rep(i, min(c, (int)z.size())) {
    if (z[i] < r[i]) {
      ans -= z[i];
      ans += r[i];
    }
  }
  cout << ans << endl;
  return (0);
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e5 + 10;
typedef struct node {
  ll r, type;
  bool operator<(const node &t) const { return r > t.r; }
} node;
node a[N];
int main() {
  ll x, y, A, B, C, tot = 0, m;
  cin >> x >> y >> A >> B >> C;
  for (ll i = 0; i < A; i++)
    scanf("%lld", &m), a[tot].r = m, a[tot].type = 0, tot++;
  for (ll i = 0; i < B; i++)
    scanf("%lld", &m), a[tot].r = m, a[tot].type = 1, tot++;
  for (ll i = 0; i < C; i++)
    scanf("%lld", &m), a[tot].r = m, a[tot].type = 2, tot++;
  sort(a, a + tot);
  ll aa = 0, bb = 0, cc = 0, ans = 0;
  for (ll i = 0; i < tot; i++) {
    if (a[i].type == 2)
      cc++, ans += a[i].r;
    else if (a[i].type == 0 && aa < x)
      aa++, ans += a[i].r;
    else if (a[i].type == 1 && bb < y)
      bb++, ans += a[i].r;
    if (aa + bb + cc == x + y)
      break;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 3e5 + 10;
typedef struct node {
  ll r, type;
  bool operator<(const node &t) const { return r > t.r; }
} node;
node a[N];
int main() {
  ll x, y, A, B, C, tot = 0, m;
  cin >> x >> y >> A >> B >> C;
  for (ll i = 0; i < A; i++)
    scanf("%lld", &m), a[tot].r = m, a[tot].type = 0, tot++;
  for (ll i = 0; i < B; i++)
    scanf("%lld", &m), a[tot].r = m, a[tot].type = 1, tot++;
  for (ll i = 0; i < C; i++)
    scanf("%lld", &m), a[tot].r = m, a[tot].type = 2, tot++;
  sort(a, a + tot);
  ll aa = 0, bb = 0, cc = 0, ans = 0;
  for (ll i = 0; i < tot; i++) {
    if (a[i].type == 2)
      cc++, ans += a[i].r;
    else if (a[i].type == 0 && aa < x)
      aa++, ans += a[i].r;
    else if (a[i].type == 1 && bb < y)
      bb++, ans += a[i].r;
    if (aa + bb + cc == x + y)
      break;
  }
  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

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

using namespace std;

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> va(a);
  vector<int> vb(b);
  vector<int> vc(c);
  for (int i = 0; i < a; i++) {
    cin >> va[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> vb[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> vc[i];
  }
  sort(va.begin(), va.end());
  reverse(va.begin(), va.end());
  sort(vb.begin(), vb.end());
  reverse(vb.begin(), vb.end());
  sort(vc.begin(), vc.end());
  reverse(vc.begin(), vc.end());

  int qa = x - 1;
  int qb = y - 1;
  int qc = 0;
  while (true) {
    if (qc == c) {
      qc--;
      break;
    }
    long long ca = qa == -1 ? 1e10 : va[qa];
    long long cb = qb == -1 ? 1e10 : vb[qb];
    long long cc = vc[cc];
    if (cc > ca || cc > cb) {
      if (ca <= cb) {
        qa--;
      } else {
        qb--;
      }
      qc++;
    } else {
      qc--;
      break;
    }
  }

  long long ans = 0;
  for (int i = 0; i <= qa; i++) {
    ans += va[i];
  }
  for (int i = 0; i <= qb; i++) {
    ans += vb[i];
  }
  for (int i = 0; i <= qc; i++) {
    ans += vc[i];
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> va(a);
  vector<int> vb(b);
  vector<int> vc(c);
  for (int i = 0; i < a; i++) {
    cin >> va[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> vb[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> vc[i];
  }
  sort(va.begin(), va.end());
  reverse(va.begin(), va.end());
  sort(vb.begin(), vb.end());
  reverse(vb.begin(), vb.end());
  sort(vc.begin(), vc.end());
  reverse(vc.begin(), vc.end());

  int qa = x - 1;
  int qb = y - 1;
  int qc = 0;
  while (true) {
    if (qc == c) {
      qc--;
      break;
    }
    long long ca = qa == -1 ? 1e10 : va[qa];
    long long cb = qb == -1 ? 1e10 : vb[qb];
    long long cc = vc[qc];
    if (cc > ca || cc > cb) {
      if (ca <= cb) {
        qa--;
      } else {
        qb--;
      }
      qc++;
    } else {
      qc--;
      break;
    }
  }

  long long ans = 0;
  for (int i = 0; i <= qa; i++) {
    ans += va[i];
  }
  for (int i = 0; i <= qb; i++) {
    ans += vb[i];
  }
  for (int i = 0; i <= qc; i++) {
    ans += vc[i];
  }
  cout << ans << endl;

  return 0;
}
Problem p02727 (Python)

Buggy submission (status: Runtime Error):
x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())))

A = sorted(P[:x] + Q[:y])
ans = sum(A)

for i in range(c):
    if A[i] < R[-1]:
        ans = ans + R[-1] - A[i]
        R.pop(-1)

print(ans)


Fixed submission:
x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())))

A = sorted(P[:x] + Q[:y])
ans = sum(A)

for i in range(min(c, len(A))):
    if A[i] < R[-1]:
        ans = ans + R[-1] - A[i]
        R.pop(-1)

print(ans)
Problem p02727 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  size_t X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<size_t> p(A);
  vector<size_t> red(X, 0);
  for (int i = 0; i < A; ++i) {
    size_t p;
    cin >> p;
    red.at(0) = max(red.at(0), p);
    sort(red.begin(), red.end());
  }
  vector<size_t> q(B);
  vector<size_t> green(Y, 0);
  for (int i = 0; i < B; ++i) {
    size_t q;
    cin >> q;
    green.at(0) = max(green.at(0), q);
    sort(green.begin(), green.end());
  }
  vector<size_t> r(C);
  for (int i = 0; i < C; ++i) {
    size_t r;
    cin >> r;
    if (red.at(0) < green.at(0)) {
      if (r > red.at(0)) {
        red.at(0) = r;
        sort(red.begin(), red.end());
      }
    } else {
      if (r > green.at(0)) {
        green.at(0) = r;
        sort(green.begin(), green.end());
      }
    }
  }
  cout << accumulate(red.begin(), red.end(), 0ll) +
              accumulate(green.begin(), green.end(), 0ll)
       << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  int x, y;
  cin >> x >> y;
  int a, b, c;
  cin >> 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.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  vector<int> d;
  for (int i = 0; i < x; ++i)
    d.push_back(p.at(i));
  for (int i = 0; i < y; ++i)
    d.push_back(q.at(i));
  for (int i = 0; i < c; ++i)
    d.push_back(r.at(i));
  sort(d.rbegin(), d.rend());
  ll ans = 0;
  for (int i = 0; i < x + y; ++i)
    ans += d.at(i);
  cout << ans << endl;
  return 0;
}
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++)

typedef long long ll;
typedef pair<ll, int> P;

int main() {
  int X, Y, a, b, c;
  cin >> X >> Y >> c >> b >> a;
  vector<ll> A, B, C;

  rep(i, a) {
    ll t;
    cin >> t;
    A.push_back(t);
  }
  rep(i, b) {
    ll t;
    cin >> t;
    B.push_back(t);
  }
  rep(i, c) {
    ll t;
    cin >> t;
    C.push_back(t);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());

  rep(i, X) { C.push_back(A[i]); }
  rep(i, Y) { C.push_back(B[i]); }
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());

  ll ans = 0;
  rep(i, X + Y) { ans += C[i]; }

  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++)

typedef long long ll;
typedef pair<ll, int> P;

int main() {
  int X, Y, a, b, c;
  cin >> X >> Y >> a >> b >> c;
  vector<ll> A, B, C;

  rep(i, a) {
    ll t;
    cin >> t;
    A.push_back(t);
  }
  rep(i, b) {
    ll t;
    cin >> t;
    B.push_back(t);
  }
  rep(i, c) {
    ll t;
    cin >> t;
    C.push_back(t);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());

  rep(i, X) { C.push_back(A[i]); }
  rep(i, Y) { C.push_back(B[i]); }
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());

  ll ans = 0;
  rep(i, X + Y) { ans += C[i]; }

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

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

using namespace std;

#define pan(i, n) for (int i = 0; i < n; i++)
#define pans(i, n, a) for (int i = a; i < n; i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF INT_MAX
#define PI 3.141592653
#define inf 1000007
#define pll pair<ll, ll>
#define pii pair<int, int>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int main() {
  ll x, y, A, B, C, ans = 0;
  cin >> x >> y >> A >> B >> C;
  vector<ll> a(A), b(B), c(C), f;
  pan(i, A) cin >> a[i];
  pan(i, B) cin >> b[i];
  pan(i, C) cin >> c[i];
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());
  pan(i, x) f.pb(a[i]);
  pan(i, y) f.pb(b[i]);
  sort(f.begin(), f.end());
  int n = (C > f.size()) ? C : f.size();
  pan(i, n) {
    if (c[i] - f[i] > 0)
      f[i] = c[i];
  }
  pan(i, (int)f.size()) ans += f[i];
  cout << ans;
}

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

using namespace std;

#define pan(i, n) for (int i = 0; i < n; i++)
#define pans(i, n, a) for (int i = a; i < n; i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF INT_MAX
#define PI 3.141592653
#define inf 1000007
#define pll pair<ll, ll>
#define pii pair<int, int>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int main() {
  ll x, y, A, B, C, ans = 0;
  cin >> x >> y >> A >> B >> C;
  vector<ll> a(A), b(B), c(C), f;
  pan(i, A) cin >> a[i];
  pan(i, B) cin >> b[i];
  pan(i, C) cin >> c[i];
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());
  pan(i, x) f.pb(a[i]);
  pan(i, y) f.pb(b[i]);
  sort(f.begin(), f.end());
  int n = (C > f.size()) ? f.size() : C;
  pan(i, n) {
    if (c[i] - f[i] > 0)
      f[i] = c[i];
  }
  pan(i, (int)f.size()) ans += f[i];
  cout << ans;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define maxn 2005
using namespace std;
const ll inf = 1e9 + 7;
ll a[maxn], b[maxn], c[maxn];
vector<ll> v;
int main() {
  // freopen("input.txt","r",stdin);
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  for (int i = 0; i < A; i++)
    cin >> a[i];
  for (int i = 0; i < B; i++)
    cin >> b[i];
  for (int i = 0; i < C; i++)
    cin >> c[i];
  sort(a, a + A);
  sort(b, b + B);
  sort(c, c + C);
  ll sum = 0;
  for (int i = 0; i < X; i++)
    v.push_back(a[A - 1 - i]);
  for (int i = 0; i < Y; i++)
    v.push_back(b[B - 1 - i]);
  for (int i = 0; i < C; i++)
    v.push_back(c[i]);
  sort(v.begin(), v.end());
  int len = v.size();
  for (int i = 0; i < X + Y; i++)
    sum += v[len - i - 1];
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005
using namespace std;
const ll inf = 1e9 + 7;
ll a[maxn], b[maxn], c[maxn];
vector<ll> v;
int main() {
  // freopen("input.txt","r",stdin);
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  for (int i = 0; i < A; i++)
    cin >> a[i];
  for (int i = 0; i < B; i++)
    cin >> b[i];
  for (int i = 0; i < C; i++)
    cin >> c[i];
  sort(a, a + A);
  sort(b, b + B);
  sort(c, c + C);
  ll sum = 0;
  for (int i = 0; i < X; i++)
    v.push_back(a[A - 1 - i]);
  for (int i = 0; i < Y; i++)
    v.push_back(b[B - 1 - i]);
  for (int i = 0; i < C; i++)
    v.push_back(c[i]);
  sort(v.begin(), v.end());
  int len = v.size();
  for (int i = 0; i < X + Y; i++)
    sum += v[len - i - 1];
  cout << sum << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A);
  vector<ll> q(B);
  vector<ll> r(C);
  for (ll i = 0; i < A; ++i) {
    cin >> p.at(i);
  }
  for (ll i = 0; i < B; ++i) {
    cin >> q.at(i);
  }
  for (ll i = 0; i < C; ++i) {
    cin >> r.at(i);
  }
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  vector<ll> ans(0);
  ll answer = 0;
  for (ll i = 0; i < X; ++i) {
    ans.push_back(p.at(A - i - 1));
    answer += p.at(A - i - 1);
  }
  for (ll i = 0; i < Y; ++i) {
    ans.push_back(q.at(B - i - 1));
    answer += q.at(B - i - 1);
  }
  sort(ans.begin(), ans.end());
  for (ll i = 0; i < C; ++i) {
    if (ans.at(i) < r.at(C - i - 1)) {
      answer += r.at(C - i - 1);
      answer -= ans.at(i);
    }
  }
  cout << answer << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A);
  vector<ll> q(B);
  vector<ll> r(C);
  for (ll i = 0; i < A; ++i) {
    cin >> p.at(i);
  }
  for (ll i = 0; i < B; ++i) {
    cin >> q.at(i);
  }
  for (ll i = 0; i < C; ++i) {
    cin >> r.at(i);
  }
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  vector<ll> ans(0);
  ll answer = 0;
  for (ll i = 0; i < X; ++i) {
    ans.push_back(p.at(A - i - 1));
    answer += p.at(A - i - 1);
  }
  for (ll i = 0; i < Y; ++i) {
    ans.push_back(q.at(B - i - 1));
    answer += q.at(B - i - 1);
  }
  sort(ans.begin(), ans.end());
  for (ll i = 0; i < C; ++i) {
    if (i < X + Y) {
      if (ans.at(i) < r.at(C - i - 1)) {
        answer += r.at(C - i - 1);
        answer -= ans.at(i);
      }
    }
  }
  cout << answer << endl;
}
Problem p02727 (C++)

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
  ll 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.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());
  ll psum = 0, qsum = 0;
  ll pk = A - X, qk = B - Y, rk = C - 1;
  for (int i = 0; i < C; i++) {
    ll P, Q, R = r.at(rk);
    if (pk < A)
      P = p.at(pk);
    else
      P = inf;
    if (rk < B)
      Q = q.at(qk);
    else
      Q = inf;
    ll low = min(P, Q);
    if (low == P && P < R && pk < A) {
      swap(p.at(pk), r.at(rk));
      pk++;
      rk--;
    } else if (low == Q && Q < R && qk < B) {
      swap(q.at(qk), r.at(rk));
      qk++;
      rk--;
    }
    if (rk < 0)
      break;
  }
  for (int i = A - 1; i >= A - X; i--) {
    psum += p.at(i);
  }
  for (int i = B - 1; i >= B - Y; i--) {
    qsum += q.at(i);
  }
  cout << psum + qsum << endl;
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
  ll 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.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());
  ll psum = 0, qsum = 0;
  ll pk = A - X, qk = B - Y, rk = C - 1;
  for (int i = 0; i < C; i++) {
    ll P, Q, R = r.at(rk);
    if (pk < A)
      P = p.at(pk);
    else
      P = inf;
    if (qk < B)
      Q = q.at(qk);
    else
      Q = inf;
    ll low = min(P, Q);
    if (low == P && P < R && pk < A) {
      swap(p.at(pk), r.at(rk));
      pk++;
      rk--;
    } else if (low == Q && Q < R && qk < B) {
      swap(q.at(qk), r.at(rk));
      qk++;
      rk--;
    }
    if (rk < 0)
      break;
  }
  for (int i = A - 1; i >= A - X; i--) {
    psum += p.at(i);
  }
  for (int i = B - 1; i >= B - Y; i--) {
    qsum += q.at(i);
  }
  cout << psum + qsum << endl;
}
Problem p02727 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<int> r;
  priority_queue<int> g;
  priority_queue<int> C;
  for (int i = 0; i < a; i++) {
    int X;
    cin >> X;
    r.push(X);
  }
  for (int i = 0; i < b; i++) {
    int X;
    cin >> X;
    g.push(X);
  }
  for (int i = 0; i < c; i++) {
    int X;
    cin >> X;
    C.push(X);
  }
  // cout<<r.size()<<endl;
  priority_queue<int, vector<int>, greater<int>> A;
  while (x--) {
    A.push(r.top());
    r.pop();
  }
  while (y--) {
    A.push(g.top());
    g.pop();
  }
  while (A.top() <= C.top()) {
    A.pop();
    A.push(C.top());
    C.pop();
  }
  long long ans = 0;

  while (!A.empty()) {
    ans += A.top();
    A.pop();
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<int> r;
  priority_queue<int> g;
  priority_queue<int> C;
  for (int i = 0; i < a; i++) {
    int X;
    cin >> X;
    r.push(X);
  }
  for (int i = 0; i < b; i++) {
    int X;
    cin >> X;
    g.push(X);
  }
  for (int i = 0; i < c; i++) {
    int X;
    cin >> X;
    C.push(X);
  }
  // cout<<r.size()<<endl;
  priority_queue<int, vector<int>, greater<int>> A;
  while (x--) {
    A.push(r.top());
    r.pop();
  }
  while (y--) {
    A.push(g.top());
    g.pop();
  }
  while (A.top() <= C.top()) {
    A.pop();
    A.push(C.top());
    C.pop();
    if (C.empty())
      break;
  }
  long long ans = 0;

  while (!A.empty()) {
    ans += A.top();
    A.pop();
  }
  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

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

typedef long long ll;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const ll inff = 1e18;
const ll mod = 1e9 + 7;
#define pii pair<int, int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#endif // HNO2

int x, y, a, b, c;
vector<int> v1, v2, v3;
vector<int> v;

int32_t main() {
  IOS cin >> x >> y >> a >> b >> c;
  for (int i = 1; i <= a; i++) {
    int z;
    cin >> z;
    v1.pb(z);
  }
  for (int i = 1; i <= b; i++) {
    int z;
    cin >> z;
    v2.pb(z);
  }
  for (int i = 1; i <= c; i++) {
    int z;
    cin >> z;
    v3.pb(z);
  }
  sort(all(v1));
  sort(all(v2));
  sort(all(v3));
  reverse(all(v1));
  reverse(all(v2));
  reverse(all(v3));

  int ans = -1, sum = 0;
  for (int i = 0; i < x; i++) {
    sum += v1[i];
    v.pb(v1[i]);
  }
  for (int i = 0; i < y; i++) {
    sum += v2[i];
    v.pb(v2[i]);
  }

  sort(all(v));
  reverse(all(v));

  ans = max(ans, sum);
  for (int i = 0; i < min(c, a + b); i++) {
    sum -= v.back();
    v.pop_back();
    sum += v3[i];
    ans = max(ans, sum);
  }
  cout << ans << endl;
}


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

typedef long long ll;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const ll inff = 1e18;
const ll mod = 1e9 + 7;
#define pii pair<int, int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#endif // HNO2

int x, y, a, b, c;
vector<int> v1, v2, v3;
vector<int> v;

int32_t main() {
  IOS cin >> x >> y >> a >> b >> c;
  for (int i = 1; i <= a; i++) {
    int z;
    cin >> z;
    v1.pb(z);
  }
  for (int i = 1; i <= b; i++) {
    int z;
    cin >> z;
    v2.pb(z);
  }
  for (int i = 1; i <= c; i++) {
    int z;
    cin >> z;
    v3.pb(z);
  }
  sort(all(v1));
  sort(all(v2));
  sort(all(v3));
  reverse(all(v1));
  reverse(all(v2));
  reverse(all(v3));

  int ans = -1, sum = 0;
  for (int i = 0; i < x; i++) {
    sum += v1[i];
    v.pb(v1[i]);
  }
  for (int i = 0; i < y; i++) {
    sum += v2[i];
    v.pb(v2[i]);
  }

  sort(all(v));
  reverse(all(v));

  ans = max(ans, sum);
  for (int i = 0; i < min(c, x + y); i++) {
    sum -= v.back();
    v.pop_back();
    sum += v3[i];
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
Problem p02727 (Python)

Buggy submission (status: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and (p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1]):
    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

print(sum(p) + sum(q) + sum(plus_r))


Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])):
    if p == []:
        q.pop()
        plus_r.append(r.pop())
        continue
    elif q == []:
        p.pop()
        plus_r.append(r.pop())
        continue

    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

print(sum(p) + sum(q) + sum(plus_r))
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
typedef long long ll;
ll ans, a[N], b[N], c[N], d[N], A[N], B[N], C[N], x, y, q, w, e;
bool cmp(int x, int y) { return x > y; }
int main() {
  cin >> x >> y >> q >> w >> e;
  for (int i = 1; i <= q; i++)
    cin >> a[i];
  sort(a + 1, a + q + 1, cmp);
  int cnt = 0;
  for (int i = 1; i <= x; i++) {
    d[++cnt] = a[i];
  }
  for (int i = 1; i <= w; i++)
    cin >> b[i];
  sort(b + 1, b + w + 1, cmp);
  for (int i = 1; i <= y; i++) {
    d[++cnt] = b[i];
  }
  for (int i = 1; i <= e; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= x + y + e; i++) {
    d[++cnt] = c[i];
  }
  sort(d + 1, d + x + y + e + 1, cmp);
  for (int i = 1; i <= x + y; i++) {
    ans += d[i];
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
typedef long long ll;
ll ans, a[N], b[N], c[N], d[N * 4], A[N], B[N], C[N], x, y, q, w, e;
bool cmp(int x, int y) { return x > y; }
int main() {
  cin >> x >> y >> q >> w >> e;
  for (int i = 1; i <= q; i++)
    cin >> a[i];
  sort(a + 1, a + q + 1, cmp);
  int cnt = 0;
  for (int i = 1; i <= x; i++) {
    d[++cnt] = a[i];
  }
  for (int i = 1; i <= w; i++)
    cin >> b[i];
  sort(b + 1, b + w + 1, cmp);
  for (int i = 1; i <= y; i++) {
    d[++cnt] = b[i];
  }
  for (int i = 1; i <= e; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= x + y + e; i++) {
    d[++cnt] = c[i];
  }
  sort(d + 1, d + x + y + e + 1, cmp);
  for (int i = 1; i <= x + y; i++) {
    ans += d[i];
  }
  cout << ans << endl;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 5;
typedef long long ll;
int nums1[MAXN], nums2[MAXN], nums3[MAXN];
bool cmp(int a, int b) { return a >= b; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  for (int i = 0; i < a; ++i)
    cin >> nums1[i];
  for (int i = 0; i < b; ++i)
    cin >> nums2[i];
  for (int i = 0; i < c; ++i)
    cin >> nums3[i];
  sort(nums1, nums1 + a, cmp);
  sort(nums2, nums2 + b, cmp);
  sort(nums3, nums3 + c, cmp);
  nums1[x] = 0;
  nums2[y] = 0;
  nums3[c] = 0;
  int p1 = 0, p2 = 0, p3 = 0;
  ll ans = 0;
  int cnt = 0;
  while (cnt < x + y) {
    if (nums1[p1] >= nums2[p2] && nums1[p1] >= nums3[p3]) {
      ans += nums1[p1++];
    } else if (nums2[p2] >= nums1[p1] && nums2[p2] >= nums3[p3]) {
      ans += nums2[p2++];
    } else
      ans += nums3[p3++];
    ++cnt;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 5;
typedef long long ll;
int nums1[MAXN], nums2[MAXN], nums3[MAXN];
bool cmp(int a, int b) { return a > b; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  for (int i = 0; i < a; ++i)
    cin >> nums1[i];
  for (int i = 0; i < b; ++i)
    cin >> nums2[i];
  for (int i = 0; i < c; ++i)
    cin >> nums3[i];
  sort(nums1, nums1 + a, cmp);
  sort(nums2, nums2 + b, cmp);
  sort(nums3, nums3 + c, cmp);
  nums1[x] = 0;
  nums2[y] = 0;
  nums3[c] = 0;
  int p1 = 0, p2 = 0, p3 = 0;
  ll ans = 0;
  int cnt = 0;
  while (cnt < x + y) {
    if (nums1[p1] >= nums2[p2] && nums1[p1] >= nums3[p3]) {
      ans += nums1[p1++];
    } else if (nums2[p2] >= nums1[p1] && nums2[p2] >= nums3[p3]) {
      ans += nums2[p2++];
    } else
      ans += nums3[p3++];
    ++cnt;
  }
  cout << ans << endl;
  return 0;
}
Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005], b[100005], c[100005];
vector<ll> p;
int main() {
  ll x, y, n, m, k, sum = 0;
  cin >> x >> y >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= k; i++) {
    cin >> c[i];
  }
  sort(a + 1, a + 1 + n);
  reverse(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  reverse(b + 1, b + 1 + m);
  sort(c + 1, c + 1 + k);
  reverse(c + 1, c + 1 + k);
  p.push_back(0);
  for (int i = 1; i <= x; i++)
    p.push_back(a[i]);
  for (int i = 1; i <= y; i++)
    p.push_back(b[i]);
  sort(p.begin(), p.end());
  for (int i = 1; i <= x + y; i++) {
    sum += p[i];
  }
  ll ans = sum, num = sum;
  for (ll i = 1; i <= k; i++) {
    num -= p[i];
    num += c[i];
    ans = max(ans, num);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005], b[100005], c[100005];
vector<ll> p;
int main() {
  ll x, y, n, m, k, sum = 0;
  cin >> x >> y >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= k; i++) {
    cin >> c[i];
  }
  sort(a + 1, a + 1 + n);
  reverse(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  reverse(b + 1, b + 1 + m);
  sort(c + 1, c + 1 + k);
  reverse(c + 1, c + 1 + k);
  p.push_back(0);
  for (int i = 1; i <= x; i++)
    p.push_back(a[i]);
  for (int i = 1; i <= y; i++)
    p.push_back(b[i]);
  sort(p.begin(), p.end());
  for (int i = 1; i <= x + y; i++) {
    sum += p[i];
  }
  ll ans = sum, num = sum;
  for (ll i = 1; i <= min(k, x + y); i++) {
    num -= p[i];
    num += c[i];
    ans = max(ans, num);
  }
  cout << ans << endl;
}