Problem p02727 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a, b); }       // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);

void printPQ(priority_queue<int> pq);

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

  vector<int> QA(A);
  vector<int> QB(B);
  vector<int> QC;

  for (int i = 0; i < A; i++)
    cin >> QA.at(i);
  for (int i = 0; i < B; i++)
    cin >> QB.at(i);
  for (int i = 0; i < C; i++) {
    int q;
    cin >> q;
    QC.push_back(q);
  };

  sort(QA.begin(), QA.end(), greater<int>());
  sort(QB.begin(), QB.end(), greater<int>());
  sort(QC.begin(), QC.end(), greater<int>());

  for (int i = 0; i < X; i++) {
    QC.push_back(QA.at(i));
  }
  for (int i = 0; i < Y; i++) {
    QC.push_back(QB.at(i));
  }

  sort(QC.begin(), QC.end(), greater<int>());

  int64_t sum = 0;
  for (int i = 0; i < X + Y; i++) {
    sum += QC.at(i);
  }

  cout << sum << endl;
}

// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for (int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for (int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for (int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}

void printPQ(priority_queue<int> pq) {
  cout << "----------  QA  ----------" << endl;
  while (!pq.empty()) {
    cout << pq.top() << endl;
    pq.pop();
  }
}


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

typedef long long ll;
typedef pair<int, int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a, b); }       // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);

void printPQ(priority_queue<int> pq);

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

  vector<int> QA(A);
  vector<int> QB(B);
  vector<int> QC;

  for (int i = 0; i < A; i++)
    cin >> QA.at(i);
  for (int i = 0; i < B; i++)
    cin >> QB.at(i);
  for (int i = 0; i < C; i++) {
    int q;
    cin >> q;
    QC.push_back(q);
  };

  sort(QA.begin(), QA.end(), greater<int>());
  sort(QB.begin(), QB.end(), greater<int>());
  // sort(QC.begin(), QC.end(), greater<int>());

  for (int i = 0; i < X; i++) {
    QC.push_back(QA.at(i));
  }
  for (int i = 0; i < Y; i++) {
    QC.push_back(QB.at(i));
  }

  sort(QC.begin(), QC.end(), greater<int>());

  int64_t sum = 0;
  for (int i = 0; i < X + Y; i++) {
    sum += QC.at(i);
  }

  cout << sum << endl;
}

// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for (int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for (int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for (int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}

void printPQ(priority_queue<int> pq) {
  cout << "----------  QA  ----------" << endl;
  while (!pq.empty()) {
    cout << pq.top() << endl;
    pq.pop();
  }
}