Language: C++

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
	vector<int64_t> ps(a); for (auto& p : ps) cin >> p;
	vector<int64_t> qs(b); for (auto& q : qs) cin >> q;
	vector<int64_t> rs(c); for (auto& r : rs) cin >> r;

	sort(ps.begin(), ps.end());
	sort(qs.begin(), qs.end());
	sort(rs.begin(), rs.end());

	int64_t okv = 0; int64_t ngv = 1000000001;
	while (okv + 1 < ngv) {
		int64_t m = (okv + ngv) / 2;

		int64_t cc = 0;
		{
			auto it = std::lower_bound(ps.begin(), ps.end(), m);
			cc += min(ps.end() - it, x);
		}
		{
			auto it = std::lower_bound(qs.begin(), qs.end(), m);
			cc += min(qs.end() - it, y);
		}
		{
			auto it = std::lower_bound(rs.begin(), rs.end(), m);
			cc += rs.end() - it;
		}

		if ((x + y) <= cc) {
			okv = m;
		}
		else {
			ngv = m;
		}
	}

	int64_t ans = 0;
	int64_t cc = 0;
	FOR_LT(i, 0, a) {
		if (x <= i) break;
		if (okv <= ps[a - i - 1]) {
			ans += ps[a - i - 1];
			cc++;
		}
		else {
			break;
		}
	}
	FOR_LT(i, 0, b) {
		if (y <= i) break;
		if (okv <= qs[b - i - 1]) {
			ans += qs[b - i - 1];
			cc++;
		}
		else {
			break;
		}
	}
	int64_t rc = (x + y) - cc;
	FOR_LT(i, 0, rc) {
		ans += rs[c - i - 1];
	}

	cout << ans << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:34: error: no matching function for call to 'min(__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >::difference_type, int&)'
   57 |                         cc += min(ps.end() - it, x);
      |                               ~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:57:34: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   57 |                         cc += min(ps.end() - it, x);
      |                               ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:14:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:57:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   57 |                         cc += min(ps.end() - it, x);
      |                               ~~~^~~~~~~~~~~~~~~~~~
a.cc:61:34: error: no matching function for call to 'min(__gnu_cxx::__normal_iterator<long int*, std::vector<long int> >::difference_type, int&)'
   61 |                         cc += min(qs.end() - it, y);
      |                               ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:61:34: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   61 |                         cc += min(qs.end() - it, y);
      |                               ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:61:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   61 |                         cc += min(qs.end() - it, y);
      |                               ~~~^~~~~~~~~~~~~~~~~~