Language: C++

#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
#define int long long
const int inf = 999999999999999999;
typedef long long ll;
typedef long double ld;
int n, w;
struct A {
	int v, w;
};
bool operator<(A a, A b) {
	if (a.w != b.w) return a.w < b.w;
	return a.v > b.v;
}
bool operator>(A a, A b) {
	if (a.w != b.w) return a.w > b.w;
	return a.v < b.v;
}
bool operator==(A a, A b) {
	if (a.v == b.v&&a.w == b.w) return 1;
	return 0;
}
A b[40];//??\???
A a[2][1100000];
int sum[2];
void solve(int i, int v, int w,int c,int end) {
	if (i == end) {
		a[c][sum[c]] = A{ v,w };
		return;
	}
	solve(i + 1, v + a[c][i].v, w + a[c][i].w, c, end);
	solve(i + 1, v, w, c, end);
}
signed main() {
	cin >> n >> w;
	for (int i = 0; i < n; i++)
		cin >> b[i].v >> b[i].w;
	solve(0, 0, 0, 0, n / 2);
	solve(n / 2, 0, 0, 1, n);
	sort(a[0], a[0] + sum[0]);
	sort(a[1], a[1] + sum[1]);
	int r = 0, y = sum[0];
	for (int i = 0; i < sum[0]; i++) {
		if (a[0][i].v <= r) {
			a[0][i].w = inf;
			y--;
		}
		else
			r = a[0][i].v;
	}
	sort(a[0], a[0] + sum[0]);
	int ans = 0;
	for (int i = 0; i < sum[1]; i++) {
		int k = lower_bound(a[0], a[0] + y, w - a[1][i].w) - a[0];
		k--;
		if (a[0][k].w + a[1][i].w <= w)
			ans = max(ans, a[0][k].v + a[1][i].v);
	}
	cout << ans << endl;
	getchar(); getchar();
}

Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 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/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = A*; _Value = const long long int]':
/usr/include/c++/14/bits/stl_algobase.h:1504:14:   required from '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = A*; _Tp = long long int; _Compare = __gnu_cxx::__ops::_Iter_less_val]'
 1504 |           if (__comp(__middle, __val))
      |               ~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1539:32:   required from '_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = A*; _Tp = long long int]'
 1539 |       return std::__lower_bound(__first, __last, __val,
      |              ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
 1540 |                                 __gnu_cxx::__ops::__iter_less_val());
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:66:22:   required from here
   66 |                 int k = lower_bound(a[0], a[0] + y, w - a[1][i].w) - a[0];
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:69:22: error: no match for 'operator<' (operand types are 'A' and 'const long long int')
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:1241:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)'
 1241 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1241:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:69:22: note:   'A' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1249:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)'
 1249 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1249:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:69:22: note:   'A' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   69 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
a.cc:23:6: note: candidate: 'bool operator<(A, A)'
   23 | bool operator<(A a, A b) {
      |      ^~~~~~~~
a.cc:23:23: note:   no known conversion for argument 2 from 'const long long int' to 'A'
   23 | bool operator<(A a, A b) {
      |                     ~~^