criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll(i) = 0; i < (ll)(n); ++(i))
#define INF 10e12
#define MOD 1000000000 + 7
#define MX 51000
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))

using namespace std;

struct nap
{
    ll w;
    ll v;
};

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N);
    vector<ll> v(N);
    for (ll i = 0; i < N; ++i)
    {
        ll a, b;
        cin >> a >> b;
        w[i] = a;
        v[i] = b;
    }
    vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
    rep(i, W + 1)
        dp[0][i] = 0;
    rep(i, N)
    {
        rep(j, W + 1)
        {
            if (j >= w[i])
                dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
            else
                dp[i + 1][j] = dp[i][j];
        }
        cout << dp[N][W]endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:66:25: error: expected ';' before 'endl'
   66 |         cout << dp[N][W]endl;
      |                         ^~~~
      |                         ;
Language: Java

import java.util.*;

public class Main {

    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);


        int N = sc.nextInt();
        int W = sc.nextInt();

        long[] w = new long[N];
        long[] v = new long[N];
        for (int i = 0; i < N; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        long ans = (rec(w,v,0,W);

        System.out.println(ans));
    }


    static Map<String,Long> m = new HashMap<>();
    static
    long rec(long[] w,long[] v ,int i, long W){

        if(i==w.length) return 0;

        String key = new StringBuilder(new Integer(i).toString()).append(" ").append(W).toString();
        if(m.containsKey(key)){
            return m.get(key);
        }


        long max = -1;
        //use
        if(W-w[i]>=0){
            max = Math.max(max, rec(w,v,i+1,W-w[i] ) +v[i] );
        }
        //not use
        max = Math.max(max,rec(w,v,i+1, W));

        m.put(key,max);

        return max;


    }

}

Compiler output:
Main.java:20: error: ')' expected
        long ans = (rec(w,v,0,W);
                                ^
Main.java:22: error: ';' expected
        System.out.println(ans));
                               ^
2 errors
Language: C++

// #include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


ll n,w, a[100009], b[100009];
ll dp[109][100009];

// map<int, map<ll, ll> > dp;
 
ll solve(int idx, ll W) {
    if(idx == n)
        return 0;
    
    if(dp[idx][W] != -1)
    	return dp[idx][W];

    // if(dp.find(idx) != dp.end() && dp[idx].find(W) != dp[idx].end())
    // 	return dp[idx][W];

    ll ans = solve(idx + 1, W);
    if(a[idx] <= W)
    	ans = max(ans, b[idx] + solve(idx + 1, W - a[idx]));
    return dp[idx][W] = ans;
}
 
int main() {
 
    // int t;
    // cin>>t;
    // while(t--) {
        cin>>n>>w;
        memset(dp, -1, sizeof(dp));

        for(int i = 0; i < n; i++) {
            cin>>a[i]>>b[i];
        }
 
        cout<<solve(0, w)<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:9: error: 'memset' was not declared in this scope
   40 |         memset(dp, -1, sizeof(dp));
      |         ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    6 | #include<map>
  +++ |+#include <cstring>
    7 |
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long int  dp[1001][1001];

   long long int knapsack(int val[], int cap[], int i,int n,int max1)
{
    if(i==n||max1<=0)
    return 0;
   if(dp[i][max1]!=-1)
   return dp[i][max1];
    
int op1,op2;
op1=op2=0;
if(cap[i]<=max1)
{
    op1=val[i]+knapsack(val,cap,i+1,n,max1-cap[i]);
}
    
    op2=knapsack(val,cap,i+1,n, max1);
    
    return dp[i][max1]=max(op1,op2);
}

 int   main() 
    {
        
        long long int  n,w;
        cin>>n>>w;
        long long int  wt[n],val[n];
        for(long long int  i=0;i<n;i++)
        cin>>wt[i]>>val[i];

        memset(dp,-1,sizeof(dp));
        cout<<knapsack(val,wt,0,n,w);
        return 0;
    }

Compiler output:
a.cc: In function 'int main()':
a.cc:34:24: error: cannot convert 'long long int*' to 'int*'
   34 |         cout<<knapsack(val,wt,0,n,w);
      |                        ^~~
      |                        |
      |                        long long int*
a.cc:5:31: note:   initializing argument 1 of 'long long int knapsack(int*, int*, int, int, int)'
    5 |    long long int knapsack(int val[], int cap[], int i,int n,int max1)
      |                           ~~~~^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
f
}

int main()
{
	c_p_c();
	int n, W;
	cin >> n >> W;
	int weights[105];
	ll values[105];
	for (int i = 1; i <= n; i++) {
		cin >> weights[i] >> values[i];
	}
	ll profit = 0;
	ll *prev = new ll[100005] {0};
	ll *curr = new ll[100005] {0};
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= W; j++) {
			ll inc = INT_MIN , exc;
			exc = prev[j];
			if (j - weights[i] >= 0) {
				inc = values[i]  + prev[j - weights[i] ];
			}
			curr[j] = max(inc, exc);
		}
		ll* temp = prev;
		prev = curr;
		curr = temp;
	}
	cout << prev[W] << endl;
	delete prev[];
	delete curr[];
	return 0;
}

Compiler output:
a.cc: In function 'void c_p_c()':
a.cc:26:1: error: 'f' was not declared in this scope
   26 | f
      | ^
a.cc: In function 'int main()':
a.cc:56:21: error: expected primary-expression before ']' token
   56 |         delete prev[];
      |                     ^
a.cc:57:21: error: expected primary-expression before ']' token
   57 |         delete curr[];
      |                     ^
Language: C++

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int v[n+1],w[n+1];
   int dp[n+1][w+1];

  for(int i=1;i<=n;i++)
  {cin>>w[i]>>v[i];
   }
  
  dp[0]=0;
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=k;j++){
      if(i==0||j==0)
        dp[i][j]=0;
      else if(w[i]>j)
        dp[i][j]=dp[i-1][j];
      else
        dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
        
    }
  }
    cout<<dp[n][w]<<endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:17: error: conversion from 'int*' to 'long unsigned int' in a converted constant expression
    8 |    int dp[n+1][w+1];
      |                ~^~
a.cc:8:17: error: could not convert '(((int*)(& w)) + 4)' from 'int*' to 'long unsigned int'
    8 |    int dp[n+1][w+1];
      |                ~^~
      |                 |
      |                 int*
a.cc:8:17: error: size of array 'dp' has non-integral type 'int*'
a.cc:14:8: error: incompatible types in assignment of 'int' to 'int [1]'
   14 |   dp[0]=0;
      |   ~~~~~^~
a.cc:27:16: error: invalid types 'int [1][int [(n + 1)]]' for array subscript
   27 |     cout<<dp[n][w]<<endl;
      |                ^
Language: Java

import java.util.Scanner;

public class main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);


		int n = sc.nextInt();
		int w_max = sc.nextInt();
		int[] w = new int[n+1];
		long[] v = new long[n+1];
		long[][] dp = new long[n+1][w_max+1];
		for(int i=1;i<=n;i++)
		{
			w[i] = sc.nextInt();
			v[i] = sc.nextLong();
		}
		for(int i=0;i<=n;i++)
		{
			dp[i][0]=0;
		}
		for(int i=0;i<=w_max;i++)
		{
			dp[0][i]=0;
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=w_max;j++)
			{
				if(w[i]<=j)
				{
					dp[i][j]=Math.max(v[i]+dp[i-1][j-w[i]], dp[i-1][j]); 
				}
				else
				{
					dp[i][j]=dp[i-1][j];
				}
			}
		}

		System.out.println(dp[n][w_max]);





	}
}

Compiler output:
Main.java:3: error: class main is public, should be declared in a file named main.java
public class main
       ^
1 error
Language: Java

import java.util.Scanner;

public class gh
{
	public static void main(String args[])
	{
		Scanner cin = new Scanner(System.in);


		int n = cin.nextInt();
		int w_max = cin.nextInt();
		int[] w = new int[n+1];
		long[] v = new long[n+1];
		long[][] dp = new long[n+1][w_max+1];
		for(int i=1;i<=n;i++)
		{
			w[i] = cin.nextInt();
			v[i] = cin.nextLong();
		}
		for(int i=0;i<=n;i++)
		{
			dp[i][0]=0;
		}
		for(int i=0;i<=w_max;i++)
		{
			dp[0][i]=0;
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=w_max;j++)
			{
				if(w[i]<=j)
				{
					dp[i][j]=Math.max(v[i]+dp[i-1][j-w[i]], dp[i-1][j]); 
				}
				else
				{
					dp[i][j]=dp[i-1][j];
				}
			}
		}

		System.out.println(dp[n][w_max]);





	}
}

Compiler output:
Main.java:3: error: class gh is public, should be declared in a file named gh.java
public class gh
       ^
1 error
Language: Java

�������7�;
���	��
��
���
�� 
�!�"	��#
�$�%�&�'�<init>�()V�Code�LineNumberTable�main�([Ljava/lang/String;)V�
StackMapTable�(�)�*�
SourceFile�gh.java�
��java/util/Scanner�+�,�-�
�.�/�0�[[J�1�2�3�4�5�6�7�8�9�:�gh�java/lang/Object�[Ljava/lang/String;�[I�[J�java/lang/System�in�Ljava/io/InputStream;�(Ljava/io/InputStream;)V�nextInt�()I�nextLong�()J�java/lang/Math�max�(JJ)J�out�Ljava/io/PrintStream;�java/io/PrintStream�println�(J)V� ����������
�����������*���������������	���������	�����Y����L+��=+��>`�
:`�:``��:6��+��O+��P����6��2	P����6��2	P����6��b6��S.��12/d2.d/ad2/��P��2d2/P����������	2/��
��������f������
������
�#��/��8��A��J��P��Y��a��g��p��x��~������� ���"���&���������+���1����<���2����������������������=����������

Compiler output:
Main.java:1: error: illegal character: '\ufffd'
???????7?;
^
Main.java:1: error: illegal character: '\ufffd'
???????7?;
 ^
Main.java:1: error: illegal character: '\ufffd'
???????7?;
  ^
Main.java:1: error: illegal character: '\ufffd'
???????7?;
   ^
Main.java:1: error: illegal character: '\ufffd'
???????7?;
    ^
Main.java:1: error: illegal character: '\ufffd'
???????7?;
     ^
Main.java:1: error: illegal character: '\ufffd'
???????7?;
      ^
Main.java:1: error: illegal character: '\ufffd'
???????7?;
        ^
Main.java:2: error: illegal character: '\ufffd'
???	??
^
Main.java:2: error: illegal character: '\ufffd'
???	??
  ^
Main.java:2: error: illegal character: '\u0019'
???	??
   ^
Main.java:2: error: illegal character: '\u0007'
???	??
    ^
Main.java:2: error: illegal character: '\ufffd'
???	??
     ^
Main.java:2: error: reached end of file while parsing
???	??
      ^
14 errors
Language: C++


 
#include <iostream>
using namespace std;
#define ffor( i,a,b) for(int i=a;i<b;i++)
#define ll long long
int main()
{
    ll w,n;
    cin>>n>>w;
    ll wt[n],v[n];
    ffor(i,0,n)
    {
        cin>>wt[i]>>v[i];
    }
    ll dp[n+1][w+1];
    ffor(i,0,n+1)
    {
        ffor(j,0,w+1)
        {
         if(i==0||j==0)
         {
             dp[i][j]=0;
         }   
         else if(wt[i-1]<=j)
         {
            dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-wt[i-1]]);
         }
         else
         {
             dp[i][j]=dp[i-1][j];
         }
        }
    }
    cout<<dp[n1][w];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:14: error: 'n1' was not declared in this scope; did you mean 'n'?
   35 |     cout<<dp[n1][w];
      |              ^~
      |              n
Language: C++

  
#include "bits/stdc++.h"
using namespace std;

using ll = long long;

const int INF = 1e9 + 5;

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<ll> dp(W + 1); // 0 ... W
    // dp[i] - the maximum total value of items with total weight exactly i
    for(int item = 0; item < n; ++item) {
        int weight, value;
        scanf("%d%d", &weight, &value);
        // dp[0] -> dp[3] -> dp[6]
        for(int weight_already = W - weight; weight_already >= 0; --weight_already) {
        //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            max_self(dp[weight_already+weight], dp[weight_already] + value);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= W; ++i) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:13: error: 'max_self' was not declared in this scope
   20 |             max_self(dp[weight_already+weight], dp[weight_already] + value);
      |             ^~~~~~~~
a.cc:25:9: error: 'max_self' was not declared in this scope
   25 |         max_self(answer, dp[i]);
      |         ^~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int knapsack(int n,int W,int val[],int w[])
{  int i,j;
	int dp[n+1][W+1];
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=W;j++)
		{
			if(i==0||j==0)
			dp[i][j]=0;
			else if(w[i-1]<=j)
		    dp[i][j]=max(val[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
				
				else
				dp[i][j]=dp[i-1][j];
			
		}
	}
	return dp[n][W];
	
}
int main()
{
	int n;
	long int W;
	cin>>n>>W;
	long int val[10000],w[10000];
	for(int i=0;i<n;i++)
	{
		cin>>w[i];
		cin>>val[i];
	}
	
	cout<<knapsack(n,W,val,w);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:28: error: cannot convert 'long int*' to 'int*'
   35 |         cout<<knapsack(n,W,val,w);
      |                            ^~~
      |                            |
      |                            long int*
a.cc:3:30: note:   initializing argument 3 of 'int knapsack(int, int, int*, int*)'
    3 | int knapsack(int n,int W,int val[],int w[])
      |                          ~~~~^~~~~
Language: C++

#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int knapsack(int arr[][2],int n,int w)
{
  long long int dp[n][w+1];
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<=w;j++)
      {
          dp[i][j]=0;
      }
  }
  for(int i=1;i<=w;i++)
  {
      if(arr[0][0]<=i)
      {
           dp[0][i] = arr[0][1];
      }
  }
  for(int i=1;i<n;i++)
  {
      for(int j=1;j<=w;j++)
      {
          if(j-arr[i][0]>=0)
          dp[i][j] = max(dp[i-1][j],arr[i][1]+dp[i-1][j-arr[i][0]]);
          else
          dp[i][j]= dp[i-1][j];
      }
  }
  return dp[n-1][w];
}
int main()
{
  int n,w;
  cin>>n>>w;
  long long int arr[n][2];
  for(int j=0;j<n;j++)
  {
    for(int i=0;i<2;i++)
    {
        cin>>arr[j][i];
    }
  }
  cout<<knapsack(arr,n,w)<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:46:18: error: cannot convert 'long long int (*)[2]' to 'int (*)[2]'
   46 |   cout<<knapsack(arr,n,w)<<endl;
      |                  ^~~
      |                  |
      |                  long long int (*)[2]
a.cc:5:18: note:   initializing argument 1 of 'int knapsack(int (*)[2], int, int)'
    5 | int knapsack(int arr[][2],int n,int w)
      |              ~~~~^~~~~~~~
Language: C++

#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int knapsack(int arr[][2],int n,int w)
{
  long long int dp[n][w+1] ={0};
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<=w;j++)
      {
          dp[i][j]=0;
      }
  }
  for(int i=1;i<=w;i++)
  {
      if(arr[0][0]<=i)
      {
           dp[0][i] = arr[0][1];
      }
  }
  for(int i=1;i<n;i++)
  {
      for(int j=1;j<=w;j++)
      {
          if(j-arr[i][0]>=0)
          dp[i][j] = max(dp[i-1][j],arr[i][1]+dp[i-1][j-arr[i][0]]);
          else
          dp[i][j]= dp[i-1][j];
      }
  }
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<=w;j++)
      {
          cout<<dp[i][j]<<" ";
      }
      cout<<endl;
  }
  return dp[n-1][w];
}
int main()
{
  int n,w;
  cin>>n>>w;
  long long int arr[n][2];
  for(int j=0;j<n;j++)
  {
    for(int i=0;i<2;i++)
    {
        cin>>arr[j][i];
    }
  }
  cout<<"\n"<<"ans : "<<knapsack(arr,n,w)<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:34: error: cannot convert 'long long int (*)[2]' to 'int (*)[2]'
   54 |   cout<<"\n"<<"ans : "<<knapsack(arr,n,w)<<endl;
      |                                  ^~~
      |                                  |
      |                                  long long int (*)[2]
a.cc:5:18: note:   initializing argument 1 of 'int knapsack(int (*)[2], int, int)'
    5 | int knapsack(int arr[][2],int n,int w)
      |              ~~~~^~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

int main(void)
{
	int n,W;
	scanf("%d%d",&n,&W);
	vector<int> dp(W+1,0);
	for(int item = 0;item < n;item++)
	{
		int weight,value;
		scanf("%d%d",&weight,&value);
		
		for(int wa = W - weight ; wa >= 0 ; wa--)
		{
			dp[wa+weight] = max(dp[wa+weight],dp[wa] + value);
		}
			//cout<<dp[i]<<" ";
			//cout<<endl;
	}
	long long ans = 0;
	for(int i=0;i<=W;i++)
	{
		ans = max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:26: error: no matching function for call to 'max(long long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   24 |                 ans = max(ans,dp[i]);
      |                       ~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:24:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   24 |                 ans = max(ans,dp[i]);
      |                       ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:24:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   24 |                 ans = max(ans,dp[i]);
      |                       ~~~^~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
int main() {
    int n, w;
    cin >> n >> w;
    int arr[n][2];
    int i, j;
    for (i = 0; i < n; i++) {
        cin >> arr[i][0] >> arr[i][1];
    }
    int dp[n][w + 2];
    for (i = 0; i < n; i++) {
        for (j = 0; j <= w; j++) {

            dp[i][j]=0;
        }
    }
    for (i = 0; i < n; i++) {
        dp[i][0] = 0;
    }
    for (i = 0; i <= w; i++) {
        dp[0][w] = 0;
    }
    dp[0][arr[0][0]] = arr[0][1];
    for (i = 1; i < n; i++) {
        for (j = 0; j <= w; j++) {
            int a1 = 0;
            int a2 = dp[i - 1][j];
            if (j - arr[i][0] >= 0) {
              //  cout<<arr[i][0]<<" ";
                a1 = arr[i][1] + dp[i - 1][j - arr[i][0]];
            }
            dp[i][j] = max(a1, a2);
        }
        //cout<<endl;
    }

    int m = 0;
    for (i = 0; i <= w; i++) {
        if (m < dp[n - 1][i]) {
            m = dp[n - 1][i];
        }
    }
    cout << m;
    return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: Java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class kanpsack {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		StringTokenizer st = new StringTokenizer(line, " ");
		int n = Integer.parseInt(st.nextToken());
		int sum = Integer.parseInt(st.nextToken());
		int wt[] = new int[n];
		int val[] = new int[n];
		for (int i = 0; i < n; i++) {
			String lines = br.readLine();
			StringTokenizer sts = new StringTokenizer(lines, " ");
			wt[i] = Integer.parseInt(sts.nextToken());
			val[i] = Integer.parseInt(sts.nextToken());
		}
		System.out.println(KN(n, sum, wt, val));
	}

	static long KN(int n, int W, int wt[], int val[]) {
		long dp[][] = new long[n + 1][W + 1];

		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= W; j++) {
				if (i == 0 || j == 0) {
					dp[i][j] = 0;
				} else if (wt[i - 1] <= j) {
					dp[i][j] = Math.max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
				} else {
					dp[i][j] = dp[i - 1][j];
				}
			}
		}
		return dp[n][W];
	}

}


Compiler output:
Main.java:6: error: class kanpsack is public, should be declared in a file named kanpsack.java
public class kanpsack {
       ^
1 error
Language: C++

#include <iostream>//for cin cout endl
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int N;
long long W,weight[110],value[110];
long long dp[110][100010]={0};
int main(){

    int cin>>N>>W;
    for (int i =0 ; i<N;++i)cin>>weight[i]>>value[i];

    for (int i=0;i<N;++i){
        for (int sum_w=0;sum_w<=W;++sum_w){

            if(sum_w-weight[i]>=0){
                chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
            };
            chmax(dp[i+1][sum_w],dp[i][sum_w]);

        }
    }

    cout<<dp[N][W]<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:12: error: expected initializer before '>>' token
   23 |     int cin>>N>>W;
      |            ^~
Language: C++

#include<bits/stdc++.h>
#define ll long long int
#define ii int
#define jmp cout<<"\n"
#define vl vector<ll>
#define pb push_back
#define printv(v) for(auto x:v) cout<<x<<" "; jmp;
#define endll "\n"
#define SORT(v) sort(v.begin(),v.end())
#define REV(x)  reverse(x.begin(),x.end())
#define ff first
#define ss second
#define iin insert
using namespace std;
ll knapSack(ll W, ll wt[], ll val[], ll n)
{
	ll dp[n + 1][W + 1];
	for (ll i = 0; i <= n; i++)
		dp[i][0] = 0;
	for (ll j = 0; j <= W; j++)
		dp[0][j] = 0;
	// if(n==0||W==0)
	// return 0;
	// if(wt[n-1]>W)
	// return knapSack(W,wt,val,n-1);
	// else
	// return max(knapSack(W,wt,val,n-1),val[n-1]+knapSack(W-wt[n-1],wt,val,n-1));
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= W; j++)
		{
			if (wt[i - 1] > j)
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - wt[i - 1]]);
		}
	}
	return dp[n][W];

}
void solve()
{
	ll n, W;
	cin >> n >> W;
	ll w[n], val[n];
	for (ll i = 0; i < n; i++)
		cin >> w[i] >> val[i];
	cout << knapSack(W, w, val, n);

}
int main()
{
fast;
	// ll t;
	// cin >> t;
	// while (t--)
	solve();
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:1: error: 'fast' was not declared in this scope
   53 | fast;
      | ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

long long findMaxProfit(vector<int>&w,vector<int>&profit,int we,int n)
{
    long long dp[n+1][we+1];
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=we; j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(w[i-1]<=j)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+profit[i-1]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    return dp[n][we];
}
int main()
{
    int n,w;
    cin>>n>>w;
    vector<int>weight;
    vector<long long>profit;
    int x;
    long long y;
    for(int i=0; i<n; i++)
    {
        cin>>x>>y;
        weight.push_back(x);
        profit.push_back(y);
    }
    long long val=findMaxProfit(weight,profit,n,w);
    cout<<val<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:40: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   41 |     long long val=findMaxProfit(weight,profit,n,w);
      |                                        ^~~~~~
a.cc:4:51: note: in passing argument 2 of 'long long int findMaxProfit(std::vector<int>&, std::vector<int>&, int, int)'
    4 | long long findMaxProfit(vector<int>&w,vector<int>&profit,int we,int n)
      |                                       ~~~~~~~~~~~~^~~~~~
Language: C++

#include<bit/stdc++.h>
using namespace std;

int findMaxProfit(vector<int>&w,vector<int>&profit,int w,int n){
    int dp[n+1][w+1];
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=w; j++)
        {
            if(i==0 || j==0) {dp[i][j]=0;}
            else if(w[i-1]<=j)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+profit[i-1]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    return dp[n][w];
}
int main()
{
    int n,w;
    cin>>m>>w;
    vector<int>weight;
    vector<int>profit;
    int x,y;
    for(int i=0; i<n; i++)
    {
        cin>>x>>y;
        weight.push_back(x);
        weight.push_back(y);
    }
    int val=findMaxProfit(weight,profit,w,n);
    cout<<val<<endl;
    return 0;
}


Compiler output:
a.cc:1:9: fatal error: bit/stdc++.h: No such file or directory
    1 | #include<bit/stdc++.h>
      |         ^~~~~~~~~~~~~~
compilation terminated.
Language: Java

import java.util.*;
public class Test {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int W = sc.nextInt();
    int[] wt = new int[n];
    int[] val = new int[n];
    for(int i=0; i<n; i++) {
      wt[i] = sc.nextInt();
      val[i] = sc.nextInt();
    }
      System.out.println(knapSack(wt, val, W, n));
  }
  
  public static int knapSack(int[] wt, int[] val, int W, int n) {
    int[][] dp = new int[n+1][W+1];
    
    //initialisation
    for(int i=0; i<n+1; i++) {
      for(int j=0; j<W+1; j++) {
        if(i==0 || j==0) {
          dp[i][j] = 0;
        }
      }
    }
    
    //choice diagram code
    for(int i=1; i<n+1; i++) {
      for(int j=1; j<W+1; j++) {
        if(wt[i-1] <= j) {
          dp[i][j] = Math.max(val[i-1] + dp[i-1][j-wt[i-1]], dp[i-1][j]);
        } else {
          dp[i][j] = dp[i-1][j];
        }
      }
    }
    return dp[n][W];
  }
}

Compiler output:
Main.java:2: error: class Test is public, should be declared in a file named Test.java
public class Test {
       ^
1 error
Language: Java

import java.util.*;
public class Test {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int W = sc.nextInt();
    int[] wt = new int[n];
    for(int i=0; i<n; i++) {
      wt[i] = sc.nextInt();
    }
    
    int[] val = new int[n];
    for(int i=0; i<n; i++) {
      val[i] = sc.nextInt();
    }
      System.out.println(knapSack(wt, val, W, n));
  }
  
  public static int knapSack(int[] wt, int[] val, int W, int n) {
    int[][] dp = new int[n+1][W+1];
    
    //initialisation
    for(int i=0; i<n+1; i++) {
      for(int j=0; j<W+1; j++) {
        if(i==0 || j==0) {
          dp[i][j] = 0;
        }
      }
    }
    
    //choice diagram code
    for(int i=1; i<n+1; i++) {
      for(int j=1; j<W+1; j++) {
        if(wt[i-1] <= j) {
          dp[i][j] = Math.max(val[i-1] + dp[i-1][j-wt[i-1]], dp[i-1][j]);
        } else {
          dp[i][j] = dp[i-1][j];
        }
      }
    }
    return dp[n][W];
  }
}

Compiler output:
Main.java:2: error: class Test is public, should be declared in a file named Test.java
public class Test {
       ^
1 error
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define int 		long long
#define ull 		unsigned long long
#define vi 			vector<int>
#define vvi			vector<vi>
#define mii  		map<int, int>
#define pii 		pair<int, int>
#define pq 			priority_queue<int>
#define pqs 		priority_queue<int, vi, greater<int>>
#define mod 		1000000007
#define inf 		1e18
#define ps(x, y) 	fixed<<setprecision(y)<<x
#define w(t)		int t; cin>>t; while(t--)
#define rep(i,n)	for(int i = 0; i < n; i++)
#define repd(i,n)	for(int i = n-1; i>= 0; i--)

int main()
{
	int n,W;
	cin>>n>>W;
	int w[n], v[n], i, j;
	rep(i, n)
		cin>>w[i]>>v[i];
	int dp[n+1][W+1];
	rep(i,n+1)
		dp[i][0] = 0;
	rep(i,W+1)
		dp[0][i] = 0;
	for(i = 1; i <= n; i++)
		for(j = 1; j <= W; j++)
		{
			if(j < w[i-1])
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j], v[i-1] + dp[i-1][j-w[i-1]]);
		}

	cout<<dp[n][W];
	return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define ll long long

ll opt(ll wts[], ll v[], ll n, ll W)
{
	ll dp[INT_MAX][INT_MAX] = {0};
	for(ll i=0; i<=n; i++){
		for(ll w=0; w<=W; w++){
			if(i==0 || w==0)
				dp[i][w] = 0;
			else{
				ll inc = 0, exc = 0;
				if(wts[i-1] <= w)
					inc = v[i-1] + dp[i-1][w-wts[i-1]];

				exc = dp[i-1][w];

				dp[i][w] = max(inc, exc);

			}
		}

	}

	return dp[n][W];
}

int main() {
	ll n, W; cin >> n >> W;
	ll wts[n]; ll v[n];
	for(ll i=0; i<n; i++)
		cin >> wts[i] >> v[i];

	ll ans = opt(wts, v, n, W);

	cout << ans << "\n" ;



return 0;
}

Compiler output:
a.cc: In function 'long long int opt(long long int*, long long int*, long long int, long long int)':
a.cc:8:12: error: size of array 'dp' exceeds maximum object size '9223372036854775807'
    8 |         ll dp[INT_MAX][INT_MAX] = {0};
      |            ^~
a.cc:12:33: error: 'dp' was not declared in this scope; did you mean 'dup'?
   12 |                                 dp[i][w] = 0;
      |                                 ^~
      |                                 dup
a.cc:16:56: error: 'dp' was not declared in this scope; did you mean 'dup'?
   16 |                                         inc = v[i-1] + dp[i-1][w-wts[i-1]];
      |                                                        ^~
      |                                                        dup
a.cc:18:39: error: 'dp' was not declared in this scope; did you mean 'dup'?
   18 |                                 exc = dp[i-1][w];
      |                                       ^~
      |                                       dup
a.cc:27:16: error: 'dp' was not declared in this scope; did you mean 'dup'?
   27 |         return dp[n][W];
      |                ^~
      |                dup
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    int n, w;
    cin >> n >> w;
    vector<ll> dp(w+1);
    for(int i=0; i < n; ++i) {
        int weight, value;
        cin >> weight >> value;
        for(int j=w; j >= weight; --j) {
            max_self(dp[j], dp[j-weight]+value) 
            /*above line finds out maximum of  dp[j](excluding ith element value) 
      and value + dp[j-weight] (including ith element value and the 
      profit with "KnapSack capacity - ith element weight") */    
        }
    }
    cout << dp[w] << "\n";
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:48: error: expected ';' before '}' token
   19 |             max_self(dp[j], dp[j-weight]+value)
      |                                                ^
      |                                                ;
......
   23 |         }
      |         ~
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n, w;
  cin >> n >> w;
  vector<int> h(n), v(n);
  rep(i,n) cin >> w[i] >> v[i];

  int ans = 0;
  rep(bit,1<<n) {
    int sum = 0, vv = 0;
    rep(i,n) {
      if (bit & (1 << i)) {
        vv += h[i];
        sum += v[i];
      }
    }
    if (vv >= w) {
      ans = max(ans,sum);
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:20: error: invalid types 'int[int]' for array subscript
   14 |   rep(i,n) cin >> w[i] >> v[i];
      |                    ^
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n, w;
  cin >> n >> w;
  vector<int> h(n), v(n);
  rep(i,n) cin >> h[i] >> v[i];

  int ans = 0;
  rep(bit,1<<n) {
    int sum = 0, vv = 0;
    if (bit & (1 << i)) {
      vv += h[i];
      sum += v[i];
    }
    if (vv >= w) {
      ans = max(ans,sum);
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:21: error: 'i' was not declared in this scope
   19 |     if (bit & (1 << i)) {
      |                     ^
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n, w;
  cin >> n >> w;
  vector<int> h(n), v(n);
  rep(i,n) cin >> w[i] >> v[i];

  int ans = 0;
  rep(bit,1<<n) {
    int sum = 0, vv = 0;
    if (bit & (1 << i)) {
      vv += h[i];
      sum += v[i];
    }
    if (vv >= w) {
      ans = max(ans,sum);
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:20: error: invalid types 'int[int]' for array subscript
   14 |   rep(i,n) cin >> w[i] >> v[i];
      |                    ^
a.cc:19:21: error: 'i' was not declared in this scope
   19 |     if (bit & (1 << i)) {
      |                     ^
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n, w;
  cin >> n >> w;
  vector<int> w(n), v(n);
  rep(i,n) cin >> w[i] >> v[i];

  int ans = 0;
  rep(bit,1<<n) {
    int sum = 0, vv = 0;
    if (bit & (1 << i)) {
      vv += w[i];
      sum += v[i];
    }
    if (vv >= w) {
      ans = max(ans,sum);
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:15: error: conflicting declaration 'std::vector<int> w'
   13 |   vector<int> w(n), v(n);
      |               ^
a.cc:11:10: note: previous declaration as 'int w'
   11 |   int n, w;
      |          ^
a.cc:14:20: error: invalid types 'int[int]' for array subscript
   14 |   rep(i,n) cin >> w[i] >> v[i];
      |                    ^
a.cc:19:21: error: 'i' was not declared in this scope
   19 |     if (bit & (1 << i)) {
      |                     ^
Language: C++

#include <bits/stdc++.h>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int maxn=1000010;
int n,m;
int w[maxn];
ll v[maxn];
ll dp[maxn];
int main()
{
    gbtb;
    cin>>n>>m;
    repd(i,1,n)
    {
        cin>>w[i]>>v[i];
    }
    repd(i,1,n)
    {
        for(int j=m;j>=w[i];j--)
        {
            dp[j]=max(dp[j],1ll*dp[j-w[i]]+v[i]);
        }
    }
    cout<<dp[m];
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:10: error: 'i' was not declared in this scope
   14 |     repd(i,1,n)
      |          ^
a.cc:14:5: error: 'repd' was not declared in this scope; did you mean 'read'?
   14 |     repd(i,1,n)
      |     ^~~~
      |     read
Language: C++

#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pp pair<ll,ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>

using namespace std;

int knapsack(vi& profit,vi& wt,ll maxwt){
    vvi dp(profit.size()+1,vi(maxwt+1,0));
    for(int i=1;i<=profit.size();i++){
        for(int j=1;j<=maxwt;j++){
            if(j-wt[i-1]>=0){
                dp[i][j]=max(dp[i-1][j],profit[i-1]+dp[i-1][j-wt[i-1]]);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    int ans=dp[wt.size()][0];
  	for(int i=1;i<=maxwt;i++) {
      ans=max(ans,dp[wt.size()][i]);
    }
    return ans;
}

int main(){
  ll n,W;
  cin>>n>>W;
  vector<ll> p(n);
  vector<ll> w(n);
  for(int i=0;i<n;i++){
    cin>>w[i]>>p[i];
  }
  cout<<knapsack(p,w,W);
}


Compiler output:
a.cc: In function 'int knapsack(std::vector<long long int>&, std::vector<long long int>&, ll)':
a.cc:25:14: error: no matching function for call to 'max(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
   25 |       ans=max(ans,dp[wt.size()][i]);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:25:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   25 |       ans=max(ans,dp[wt.size()][i]);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:25:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   25 |       ans=max(ans,dp[wt.size()][i]);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pp pair<ll,ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>

using namespace std;

int knapsack(vi& profit,vi& wt,ll maxwt){
    vvi dp(profit.size()+1,vi(maxwt+1,0));
    for(int i=1;i<=profit.size();i++){
        for(int j=1;j<=maxwt;j++){
            if(j-wt[i-1]>=0){
                dp[i][j]=max(dp[i-1][j],profit[i-1]+dp[i-1][j-wt[i-1]]);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    int ans=dp[wt.size()][0];
  	for(int i=1;i<=maxwt;i++) {
      ans=max(and,dp[wt.size()][i];
    }
    return ans;
}

int main(){
  ll n,W;
  cin>>n>>W;
  vector<ll> p(n);
  vector<ll> w(n);
  for(int i=0;i<n;i++){
    cin>>w[i]>>p[i];
  }
  cout<<knapsack(p,w,W);
}


Compiler output:
a.cc: In function 'int knapsack(std::vector<long long int>&, std::vector<long long int>&, ll)':
a.cc:25:18: error: expected identifier before ',' token
   25 |       ans=max(and,dp[wt.size()][i];
      |                  ^
a.cc:25:35: error: expected ')' before ';' token
   25 |       ans=max(and,dp[wt.size()][i];
      |              ~                    ^
      |                                   )
Language: C++

#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pp pair<ll,ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>

using namespace std;

int knapsack(vi& profit,vi& wt,ll maxwt){
    vvi dp(profit.size()+1,vi(maxwt+1,0));
    for(int i=1;i<=profit.size();i++){
        for(int j=1;j<=maxwt;j++){
            if(j-wt[i-1]>=0){
                dp[i][j]=max(dp[i-1][j],profit[i-1]+dp[i-1][j-wt[i-1]]);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    return max_element(dp[wt.size()],dp[wt.size()+maxwt+1];
}

int main(){
  ll n,W;
  cin>>n>>W;
  vector<ll> p(n);
  vector<ll> w(n);
  for(int i=0;i<n;i++){
    cin>>w[i]>>p[i];
  }
  cout<<knapsack(p,w,W);
}


Compiler output:
a.cc: In function 'int knapsack(std::vector<long long int>&, std::vector<long long int>&, ll)':
a.cc:23:59: error: expected ')' before ';' token
   23 |     return max_element(dp[wt.size()],dp[wt.size()+maxwt+1];
      |                       ~                                   ^
      |                                                           )
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, n) for(long long i=1; i<=(long long)(n); i++)

using namespace std;

typedef pair<long long, long long> P;

long long N, W;
long long dp[100+1][100000+1];
long long w[100000+1];
long long v[100000];

long long rec(long long i, long long j) {
    if (dp[i][j] > -1) {
        return dp[i][j]; 
    }

    long long res;
    if (i == N) {
        res = 0;
    } else if (j < w[i]) {
        res = rec(i+1, j);
    } else {
        res = max(rec(i+1, j), rec(i+1, j-w[i]) + v[i]);
    }

    return dp[i][j] = res;
}

int main(){
    cin >> N >> W;
    memset(dp, -1, sizeof(dp));

    rep(i, N) {
        cin >> w[i] >> v[i];
    }

    cout << rec(0, W) <<endl;

    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:38:5: error: 'memset' was not declared in this scope
   38 |     memset(dp, -1, sizeof(dp));
      |     ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <utility>
  +++ |+#include <cstring>
    6 |
Language: C++

#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pp pair<ll,ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>

using namespace std;

int knapsack(vi& profit,vi& wt,ll maxwt){
    vvi dp(profit.size()+1,vi(maxwt+1,0));
    for(int i=1;i<=profit.size();i++){
        for(int j=1;j<=maxwt;j++){
            if(j-wt[i-1]>=0){
                dp[i][j]=max(dp[i-1][j],profit[i-1]+dp[i-1][j-wt[i-1]]);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    return dp[wt.size()][maxwt];
}

int main(){
  ll n,W;
  cin>>n>>W;
  vector<int> p(n);
  vector<int> w(n);
  for(int i=0;i<n;i++){
    cin>>p[i]>>w[i];
  }
  cout<<knapsack(p,w,W);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:18: error: invalid initialization of reference of type 'std::vector<long long int>&' from expression of type 'std::vector<int>'
   34 |   cout<<knapsack(p,w,W);
      |                  ^
a.cc:12:18: note: in passing argument 1 of 'int knapsack(std::vector<long long int>&, std::vector<long long int>&, ll)'
   12 | int knapsack(vi& profit,vi& wt,ll maxwt){
      |                  ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
int knapsack( int wt[], int val[], int n,int W) 
{ 
   int i, w; 
   int K[n+1][W+1]; 

   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 
int main(){
	int n;
	cin>>n;
		int W;
	cin>>W;
	int wt[n];
	int v[n];
	for(int i=0;i<n;i++){
		cin>>wt[i];
		cin>>v[i];
	}

	cout<<knapsack(wt,v,n,W)<<endl;
	return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long int lint;
typedef long long int llint;

#define INF 2147483647
#define LINF 92233720370000000000

int n, w;
llint dp[110000][110000];
int we[110000], v[110000];

int main() {
    cin >> n >> w;

    for (int i = 1; i <= n; i++) {
        cin >> we[i] >> v[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= w; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - we[i] >= 0)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - we[i]] + v[i]);
        }
    }

    llint ans = 0;
    for (int i = 1; i <= w; i++) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
/tmp/ccTqMQAp.o: in function `main':
a.cc:(.text+0x4f): relocation truncated to fit: R_X86_64_PC32 against symbol `we' defined in .bss section in /tmp/ccTqMQAp.o
a.cc:(.text+0x7b): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/ccTqMQAp.o
a.cc:(.text+0x118): relocation truncated to fit: R_X86_64_PC32 against symbol `we' defined in .bss section in /tmp/ccTqMQAp.o
a.cc:(.text+0x142): relocation truncated to fit: R_X86_64_PC32 against symbol `we' defined in .bss section in /tmp/ccTqMQAp.o
a.cc:(.text+0x181): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/ccTqMQAp.o
collect2: error: ld returned 1 exit status