Language: C++

int knapsack(int k,int wt,int pri,vector<int> weight,vector<int> price,int w,int n)
{
  //  cout<<"BEFORE"<<k<<" "<<wt<<" "<<pri<<" "<<wt+weight[k]<<" "<<pri+price[k]<<" "<<endl;
    if(k>n)
    {
        return pri;
    }
    if(wt>w)
    {
    // cout<<"hii";
    return pri-price[k-1];
    }
 
    return max(knapsack(k+1,wt,pri,weight,price,w,n),knapsack(k+1,wt+weight[k],pri+price[k],weight,price,w,n));
}
int main()
{
    int n=0;int w=0;
    cin>>n;
    cin>>w;
    int k=0;
    vector<int> weight(n);
    vector<int> price(n);
    
    for(int i=0;i<n;i++)
    {
        cin>>weight[i];
        cin>>price[i];
    }
    
    int ans =knapsack(0,0,0,weight,price,w,n);
    cout<<ans;
    return 0;
}


Compiler output:
a.cc:1:35: error: 'vector' has not been declared
    1 | int knapsack(int k,int wt,int pri,vector<int> weight,vector<int> price,int w,int n)
      |                                   ^~~~~~
a.cc:1:41: error: expected ',' or '...' before '<' token
    1 | int knapsack(int k,int wt,int pri,vector<int> weight,vector<int> price,int w,int n)
      |                                         ^
a.cc: In function 'int knapsack(int, int, int, int)':
a.cc:4:10: error: 'n' was not declared in this scope
    4 |     if(k>n)
      |          ^
a.cc:8:11: error: 'w' was not declared in this scope
    8 |     if(wt>w)
      |           ^
a.cc:11:16: error: 'price' was not declared in this scope; did you mean 'pri'?
   11 |     return pri-price[k-1];
      |                ^~~~~
      |                pri
a.cc:14:36: error: 'weight' was not declared in this scope
   14 |     return max(knapsack(k+1,wt,pri,weight,price,w,n),knapsack(k+1,wt+weight[k],pri+price[k],weight,price,w,n));
      |                                    ^~~~~~
a.cc:14:43: error: 'price' was not declared in this scope; did you mean 'pri'?
   14 |     return max(knapsack(k+1,wt,pri,weight,price,w,n),knapsack(k+1,wt+weight[k],pri+price[k],weight,price,w,n));
      |                                           ^~~~~
      |                                           pri
a.cc:14:49: error: 'w' was not declared in this scope
   14 |     return max(knapsack(k+1,wt,pri,weight,price,w,n),knapsack(k+1,wt+weight[k],pri+price[k],weight,price,w,n));
      |                                                 ^
a.cc:14:51: error: 'n' was not declared in this scope
   14 |     return max(knapsack(k+1,wt,pri,weight,price,w,n),knapsack(k+1,wt+weight[k],pri+price[k],weight,price,w,n));
      |                                                   ^
a.cc:14:12: error: 'max' was not declared in this scope
   14 |     return max(knapsack(k+1,wt,pri,weight,price,w,n),knapsack(k+1,wt+weight[k],pri+price[k],weight,price,w,n));
      |            ^~~
a.cc: In function 'int main()':
a.cc:19:5: error: 'cin' was not declared in this scope
   19 |     cin>>n;
      |     ^~~
a.cc:22:5: error: 'vector' was not declared in this scope
   22 |     vector<int> weight(n);
      |     ^~~~~~
a.cc:22:12: error: expected primary-expression before 'int'
   22 |     vector<int> weight(n);
      |            ^~~
a.cc:23:12: error: expected primary-expression before 'int'
   23 |     vector<int> price(n);
      |            ^~~
a.cc:27:14: error: 'weight' was not declared in this scope
   27 |         cin>>weight[i];
      |              ^~~~~~
a.cc:28:14: error: 'price' was not declared in this scope
   28 |         cin>>price[i];
      |              ^~~~~
a.cc:31:29: error: 'weight' was not declared in this scope
   31 |     int ans =knapsack(0,0,0,weight,price,w,n);
      |                             ^~~~~~
a.cc:31:36: error: 'price' was not declared in this scope
   31 |     int ans =knapsack(0,0,0,weight,price,w,n);
      |                                    ^~~~~
a.cc:32:5: error: 'cout' was not declared in this scope
   32 |     cout<<ans;
      |     ^~~~