Problem p02727 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// #include<bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) {
    fread_unlocked(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = getcha()) >= '0')
      A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0')
      A = A * 10 + ct - '0';
  return A;
}

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

  int X = getint(), Y = getint(), A = getint(), B = getint(), C = getint();

  int abc[300000];
  auto a = abc;
  auto b = abc + A;
  auto c = abc + A + B;

  rep(i, A + B + C) a[i] = getint();

  nth_element(a, b - X, b);
  nth_element(b, c - Y, c);
  memcpy(c + C, b - X, X * sizeof(int));
  if (B - Y)
    for (auto i = b - 1; i >= b - X; i--)
      *(i + B - Y) = *i;
  nth_element(c - X - Y, c + C - X - Y, c + C);

  ll kotae = 0;
  for (auto kari = c + C - X - Y; kari < c + C; kari++)
    kotae += *kari;

  printf("%lld", kotae);

  Would you please return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// #include<bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) {
    fread_unlocked(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = getcha()) >= '0')
      A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0')
      A = A * 10 + ct - '0';
  return A;
}

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

  int X = getint(), Y = getint(), A = getint(), B = getint(), C = getint();

  int abc[300000];
  auto a = abc;
  auto b = abc + A;
  auto c = abc + A + B;

  rep(i, A + B + C) a[i] = getint();

  nth_element(a, b - X, b);
  nth_element(b, c - Y, c);
  if (B - Y)
    for (auto i = b - 1; i >= b - X; i--)
      *(i + B - Y) = *i;
  nth_element(c - X - Y, c + C - X - Y, c + C);

  ll kotae = 0;
  for (auto kari = c + C - X - Y; kari < c + C; kari++)
    kotae += *kari;

  printf("%lld", kotae);

  Would you please return 0;
}