Language: C++

#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i ,a,b) for(int i = a;i<b;i++)
#define rloop(i,a,b) for(int i = a ; i>b;i--)
#define loopll(i,a,b) for( long long int i = a; i<b;i++)
#define rloopll(i,a,b) for(long long int i = a; i>b;i--)
#define eb emplace_back
#define pii pair<int ,int>
#define pll pair<ll ,ll>
#define mk make_pair
#define intmin INT_MIN
#define intmax INT_MAX
#define cout(x) cout<<x<<" ";
using namespace std;
void vec(vector<int> & v){

    for(int i = 0;i<v.size() ; i++){
        cout<<v[i]<< " ";
    }
    cout<<endl;
}
void vec_ll(vector<long long int> & v){

    for(int i = 0;i<v.size() ; i++){
        cout<<v[i]<< " ";
    }
    cout<<endl;
}
int parsestring(string temp){
    int num= 0;
    int digs = temp.size() - 1;
    for(int i = 0 ;i<=digs;i++){
        num += pow(10 , digs -i)*(temp[i] - '0');
    }
    return num;
}

int mindig(string & s){
    int temp = INT_MAX;
//    int index = -1;
    for(int i = 0;i<s.size() ; i++){
        if(temp > s[i] - '0'){
            temp = s[i] - '0';
//            index = i;
        }
    }
    return temp;
}
//}
ll power(ll base ,ll exp){
    ll ans = 1;
    for(ll i = 1;i<=exp ; i++){
        ans *= base;
    }
    return ans;
}
//}
//
void factor(ll n ,set<ll> &s ){
        ll x = 2;
        while(n!= 1){
            if(n%x == 0){
                s.insert(x);
                n/= x;
            }
            else{
                x++;
            }
        }
    }

bool prime(int n){
    bool ok = true;
    for(int i = 2 ; i*i <= n ; i++){
        if(n%i == 0){ok =false ; break;}
    }
    return ok;
}
pair<ll ,ll > ass(pair<ll ,ll > &a , pair<ll ,ll> &b){
    pair<ll ,ll> x;
    x.first = -1e10;
    x.second = -1e10;
    if(a.second < b.first){return x;}
    if(b.second < a.first){return x;}
    if(a.first <= b.first){
        x.first = b.first;
        x.second = min(a.second , b.second);
    }
    else {
        x.first = a.first;
        x.second = min(a.second , b.second);
    }
    return x;
}

int ans = 0;
int dfs(int x){
    if(vis[x] ){return 0;}
    vis[x]  = true;
    for(int i = 0;i<adj[x].size() ;i++){
        subt[x] += dfs(adj[x][i]);
    }
    return subt[x];
}

void dfs2(int x){
    if(vis2[x]){return;}
    vis2[x] = true;
    for(int i = 0;i<adj[x].size() ;i++){
        if(neigh[x] > 1 && subt[adj[x][i]]%2 == 0 && !vis2[adj[x][i]]){
            cout<<x<< " " <<adj[x][i]<< " " <<neigh[x]<< " " <<subt[adj[x][i]]<<endl;
            ans++;
            neigh[x]--;
            neigh[adj[x][i]]--;
//            cout<<"a "<< x<< " " <<adj[x][i]<<endl;
        }
        dfs(adj[x][i]);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n ,w;
    cin>>n>>w;
    vector<bool>poss(1e9 + 10 , false);
    map<ll , ll >m;
    poss[0]= true;
    m[0] = 0;
    for(int i = 0;i<n;i++){
        ll u, v;
        cin>>u>>v;
        for(int j = w; j>= 0; j--){
            if(poss[j]){
                if(j+u <=    w){
                    poss[j+u]  = true;
                    if(m.find(j+u) != m.end()){
                        m[j+u] = max(m[j+u] , m[j] + v);
                    }
                    else{
                        m[j+u] = m[j] + v;
                    }
                }
            }
        }
    }
    ll ans = 0;

    for(auto  it = m.begin() ;it!= m.end() ;it++){
        ans = max(ans , it->second);
    }
    cout<<ans<<endl;
    }


Compiler output:
a.cc: In function 'int dfs(int)':
a.cc:99:8: error: 'vis' was not declared in this scope
   99 |     if(vis[x] ){return 0;}
      |        ^~~
a.cc:100:5: error: 'vis' was not declared in this scope
  100 |     vis[x]  = true;
      |     ^~~
a.cc:101:21: error: 'adj' was not declared in this scope
  101 |     for(int i = 0;i<adj[x].size() ;i++){
      |                     ^~~
a.cc:102:9: error: 'subt' was not declared in this scope
  102 |         subt[x] += dfs(adj[x][i]);
      |         ^~~~
a.cc:104:12: error: 'subt' was not declared in this scope
  104 |     return subt[x];
      |            ^~~~
a.cc: In function 'void dfs2(int)':
a.cc:108:8: error: 'vis2' was not declared in this scope
  108 |     if(vis2[x]){return;}
      |        ^~~~
a.cc:109:5: error: 'vis2' was not declared in this scope
  109 |     vis2[x] = true;
      |     ^~~~
a.cc:110:21: error: 'adj' was not declared in this scope
  110 |     for(int i = 0;i<adj[x].size() ;i++){
      |                     ^~~
a.cc:111:12: error: 'neigh' was not declared in this scope
  111 |         if(neigh[x] > 1 && subt[adj[x][i]]%2 == 0 && !vis2[adj[x][i]]){
      |            ^~~~~
a.cc:111:28: error: 'subt' was not declared in this scope
  111 |         if(neigh[x] > 1 && subt[adj[x][i]]%2 == 0 && !vis2[adj[x][i]]){
      |                            ^~~~