Language: C++

include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int D = 33;
const ll INF = 1e18;

int main()
{
    int n, q; cin >> n >> q;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++)cin >> a[i] >> b[i];
    stringstream ss;
    ss << bitset<D>(q);
    string s = ss.str();
    vector<vector<pair<ll,vector<bool>>>> dp(D + 1, vector<pair<ll,vector<bool>>>(2, {-INF, vector<bool>(n)})); //dp[i][j].first := i桁目まで見た時に未満フラグがjの価値の最大値 second := 既に使ったものの配列
    dp[0][0].first = 0;
    for(auto &i: s)i -= '0';




    for(int i = 0; i < D; i++) {
        for(int j = 0; j < 2; j++)dp[i + 1][j] = dp[i][j];
        for(int j = 0; j < 2; j++) {
            for(int d = 0; d <= (j ? 1 : s[i]); d++) {

                for(int k = 0; k < n; k++) {
                    if(dp[i][j].second[k] || dp[i + 1][j || d < s[i]].second[k])continue;
                    if(a[k] > q)continue;
                    if(!j && a[k] & (1LL << (D - i - 1)))continue;

                    dp[i + 1][j || d < s[i]].second[k] = true;
                    dp[i + 1][j || d < s[i]].first += b[i];
                }
            }
        }
    }
    cout << max(dp[D][0].first, dp[D][1].first) << endl;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include<bits/stdc++.h>
      | ^~~~~~~
a.cc: In function 'int main()':
a.cc:9:15: error: 'cin' was not declared in this scope
    9 |     int n, q; cin >> n >> q;
      |               ^~~
a.cc:10:5: error: 'vector' was not declared in this scope
   10 |     vector<int> a(n), b(n);
      |     ^~~~~~
a.cc:10:12: error: expected primary-expression before 'int'
   10 |     vector<int> a(n), b(n);
      |            ^~~
a.cc:11:38: error: 'a' was not declared in this scope
   11 |     for(int i = 0; i < n; i++)cin >> a[i] >> b[i];
      |                                      ^
a.cc:11:46: error: 'b' was not declared in this scope
   11 |     for(int i = 0; i < n; i++)cin >> a[i] >> b[i];
      |                                              ^
a.cc:12:5: error: 'stringstream' was not declared in this scope
   12 |     stringstream ss;
      |     ^~~~~~~~~~~~
a.cc:13:5: error: 'ss' was not declared in this scope
   13 |     ss << bitset<D>(q);
      |     ^~
a.cc:13:11: error: 'bitset' was not declared in this scope
   13 |     ss << bitset<D>(q);
      |           ^~~~~~
a.cc:14:5: error: 'string' was not declared in this scope
   14 |     string s = ss.str();
      |     ^~~~~~
a.cc:15:19: error: 'pair' was not declared in this scope
   15 |     vector<vector<pair<ll,vector<bool>>>> dp(D + 1, vector<pair<ll,vector<bool>>>(2, {-INF, vector<bool>(n)})); //dp[i][j].first := i桁目まで見た時に未満フラグがjの価値の最大値 second := 既に使ったものの配列
      |                   ^~~~
a.cc:15:26: error: expected primary-expression before ',' token
   15 |     vector<vector<pair<ll,vector<bool>>>> dp(D + 1, vector<pair<ll,vector<bool>>>(2, {-INF, vector<bool>(n)})); //dp[i][j].first := i桁目まで見た時に未満フラグがjの価値の最大値 second := 既に使ったものの配列
      |                          ^
a.cc:15:34: error: expected primary-expression before 'bool'
   15 |     vector<vector<pair<ll,vector<bool>>>> dp(D + 1, vector<pair<ll,vector<bool>>>(2, {-INF, vector<bool>(n)})); //dp[i][j].first := i桁目まで見た時に未満フラグがjの価値の最大値 second := 既に使ったものの配列
      |                                  ^~~~
a.cc:15:109: error: expected primary-expression before ')' token
   15 |     vector<vector<pair<ll,vector<bool>>>> dp(D + 1, vector<pair<ll,vector<bool>>>(2, {-INF, vector<bool>(n)})); //dp[i][j].first := i桁目まで見た時に未満フラグがjの価値の最大値 second := 既に使ったものの配列
      |                                                                                                             ^
a.cc:16:5: error: 'dp' was not declared in this scope
   16 |     dp[0][0].first = 0;
      |     ^~
a.cc:17:18: error: 's' was not declared in this scope
   17 |     for(auto &i: s)i -= '0';
      |                  ^
a.cc:25:42: error: 's' was not declared in this scope
   25 |             for(int d = 0; d <= (j ? 1 : s[i]); d++) {
      |                                          ^
a.cc:29:24: error: 'a' was not declared in this scope
   29 |                     if(a[k] > q)continue;
      |                        ^
a.cc:30:30: error: 'a' was not declared in this scope
   30 |                     if(!j && a[k] & (1LL << (D - i - 1)))continue;
      |                              ^
a.cc:33:55: error: 'b' was not declared in this scope
   33 |                     dp[i + 1][j || d < s[i]].first += b[i];
      |                                                       ^
a.cc:38:5: error: 'cout' was not declared in this scope
   38 |     cout << max(dp[D][0].first, dp[D][1].first) << endl;
      |     ^~~~
a.cc:38:13: error: 'max' was not declared in this scope
   38 |     cout << max(dp[D][0].first, dp[D][1].first) << endl;
      |             ^~~
a.cc:38:52: error: 'endl' was not declared in this scope
   38 |     cout << max(dp[D][0].first, dp[D][1].first) << endl;
      |                                                    ^~~~