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

#include <stdio.h>
main(){
  int i,j,W,w,n,a[1000],b[1000],c[1000],maxc,minb,aa,ans,c;
  c=0;
  while(1){
    c++;
    scanf("%d",&W);
    if(W==0) break;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d,%d",&a[i],&b[i]);
      c[i]=a[i]/b[i];
    }
    w=0;
    ans=0;
    maxc=0;
    minb=1001;
    while(W>w){
      for(i=0;i<n;i++){
	if(maxc<c[i] && minb>b[i] && b[i]!=0){
	  maxc=c[i];
	  minb=b[i];
	  aa=i;
	}
      }
      w+=minb;
	c[aa]=0;
	b[aa]=0;
    }
    w-=minb;
      
  }
  return 0;
}

Compiler output:
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
    2 | main(){
      | ^~~~
main.c: In function 'main':
main.c:3:58: error: conflicting types for 'c'; have 'int'
    3 |   int i,j,W,w,n,a[1000],b[1000],c[1000],maxc,minb,aa,ans,c;
      |                                                          ^
main.c:3:33: note: previous declaration of 'c' with type 'int[1000]'
    3 |   int i,j,W,w,n,a[1000],b[1000],c[1000],maxc,minb,aa,ans,c;
      |                                 ^
Language: C

#include <cstdio>
#include <algorithm>
using namespace std;

const int MAX_N = 1010;
const int MAX_W = 1010;
int memo[MAX_N][MAX_W];
int W, N, v[MAX_N], w[MAX_N], min_w;

int main()
{
    for(int c = 1; ~scanf("%d", &W) && W; ++c)
    {
        scanf("%d", &N);
        for(int i = 0; i < N; ++i)
            scanf("%d,%d", v+i, w+i);
        fill_n(memo[N], W+1, 0);
        for(int i = N - 1; i >= 0; --i)
            for(int j = 0; j <= W; ++j)
                if(j < w[i])
                    memo[i][j] = memo[i+1][j];
                else
                    memo[i][j] = max(memo[i+1][j], memo[i+1][j-w[i]] + v[i]);
        min_w = W;
        while(memo[0][W] == memo[0][min_w-1])
            --min_w;
        printf("Case %d:\n%d\n%d\n", c, memo[0][W], min_w);
    }
}

Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C

#include <stdio.h>
#include <vector>
#include <algorithm>

#define TEST 1
typedef std::pair<int,int> pi;

struct Pred
{
    bool operator()(const pi& f,const pi& s)//<
    {
        return f.second > s.second;
    }
};
pi rec_check(const std::vector<pi> &data,int start,int remw)
{
    if(start >=data.size() )
        return pi(0,0);
    if(data[start].second > remw)
        return rec_check(data,start+1,remw);
    pi div0= rec_check(data,start + 1,remw - data[start].second);
    div0.first+=data[start].first;
    div0.second+=data[start].second;
    pi div1 = rec_check(data,start + 1,remw);
    if(div0.first > div1.first )
        return div0;
    if(div0.first < div1.first)
        return div1;
    if(div0.second <div1.second)
        return div0;
    return div1;
    
}
int main(void)
{
    int ccount=1;
    int w,n;
    using namespace std;
    vector<pair<int,int> > data;
    while(scanf("%d%d",&w,&n)==2 && w!=0)
    {
        data.assign(n,std::pair<int,int>(0,0));
        for(int i=0;i<n;i++)
        {
            scanf("%d%*[,]%d",&data[i].first ,&data[i].second );
        }
        Pred pred;
        sort(data.begin(),data.end(),pred);
        printf("Case %d:",ccount);
#if TEST
        for(int i=0;i<n;i++)
        {
            printf("val=%d,wei=%d\n",data[i].first,data[i].second);
        }
#endif
        pi result=rec_check(data,0,w);
        printf("%d\n%d\n",result.first,result.second);
        data.clear();
        ccount++;
    }
    return 0;
}

Compiler output:
main.c:2:10: fatal error: vector: No such file or directory
    2 | #include <vector>
      |          ^~~~~~~~
compilation terminated.
Language: C

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <utility>
#define mp make_pair
#define f first
#define s second
#define dm(x) cerr << #x << " = " << x << endl;
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
typedef pair<int,int> pp;

pp dp[1000][1000];
int p[1001],w[1001];
int W, N;

pp operator+(pp a,pp b)
{
  pp ret(a.f+b.f, a.s+b.s);
  return ret;
}

//i番目以降でj以下の重さで価値を最大化。 {最大の価値, その時の重さ}
pp calc(int i,int j)
{
  pp ret;
  if(dp[i][j].f>=0) return dp[i][j];
  if(i==N) ret=mp(0,0);
  else if(j<w[i]) ret=calc(i+1,j);
  else{
    pp a=calc(i+1,j);
    pp b=calc(i+1,j-w[i]) + mp(p[i],w[i]);
    if(a.f>b.f) ret = a;
    else if(a.f<b.f) ret = b;
    else{
      if(a.s > b.s) ret = b;
      else ret = a;
    }
  } 
  return dp[i][j] = ret;
}

int main()
{
  int n=1;
  while(scanf("%d", &W),W){
    scanf("%d", &N);
    rep(i,N) scanf("%d, %d",p+i, w+i);
    // rep(i,N) printf("%d: p:%d w:%d\n",i , p[i], w[i]);
    rep(i,N+1) rep(j,W+1) {dp[i][j]=mp(-1,-1);}
    pp ret=calc(0,W);
    // printf(","); rep(j,W+1) printf("%d,",j); printf("\n");
    // rep(i,N+1){
    //   printf("%d,",i);
    //   rep(j,W+1)
    //     printf("%d,",calc(i,j).f);
    //   printf("\n");
    // }
    // rep(i,N+1){
    //   printf("%d,",i);
    //   rep(j,W+1)
    //     printf("%d,",calc(i,j).s);
    //   printf("\n");
    // }
    
    printf("Case %d:\n%d\n%d\n", n++, ret.f, ret.s);
  }
  return 0;
}

Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C

#include<stdio.h>

int num;
int limitWeight;
int value[50],weight[50];
int maxV=0;

void solve(int n,int sumV,int sumW){
	if(sumW > limitWeight){
		return;
	}
	else if(n==num){
		if(sumV>=maxV){
			maxV = sumV;
		}
	}
	else{
		flag[n]=1;
		solve(n+1,sumV+value[n],sumW+weight[n]);
		solve(n+1,sumV,sumW);
	}
	return;
}

int main(){
	int i,j;
	while(1){
		maxV = 0;
		scanf("%d",&limitWeight);
		scanf("%d",&num);
	if(limitWeight == 0){
		break;
	}
	for(i=0;i<num;i++){
		scanf("%d,%d",&value[i],&weight[i]);
	}
	solve(0,0,0);
	printf("%d\n",maxV);
	}
}

Compiler output:
main.c: In function 'solve':
main.c:18:17: error: 'flag' undeclared (first use in this function)
   18 |                 flag[n]=1;
      |                 ^~~~
main.c:18:17: note: each undeclared identifier is reported only once for each function it appears in
Language: C

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>
#include<limits.h>

int rec(int, int, int, int *, int *);

int main()
{
	int i, W, N, v[1024], w[1024];

	while(1){
		scanf("%d", &W);
		if(W == 0)
			break;

		memset(v, 0, sizeof(v));
		memset(w, 0, sizeof(w));

		scanf("%d", &N);

		for(i=0; i<N; i++)
			scanf("%d,%d", &v[i], &w[i]);

		printf("%d\n", rec(0, W, N, v, w));

	}

	return 0;
}

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

Compiler output:
main.c: In function 'rec':
main.c:46:23: error: implicit declaration of function 'max'; did you mean 'fmax'? [-Wimplicit-function-declaration]
   46 |                 res = max(rec(i+1, j, N, v, w), rec(i+1, j-w[i], N, v, w) + v[i]);
      |                       ^~~
      |                       fmax
Language: C

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>
#include<limits.h>

int min2(int, int);

int dp[1005][10005][2]={0};

int main()
{
	int i, j, W, N, v[1024], w[1024], c;

	c = 0;
	while(1){
		scanf("%d", &W);
		if(W == 0)
			break;

		memset(v, 0, sizeof(v));
		memset(w, 0, sizeof(w));
		memset(dp, 0, sizeof(dp));

		scanf("%d", &N);

		for(i=0; i<N; i++)
			scanf("%d,%d", &v[i], &w[i]);
		
		c++;
		printf("Case %d:\n", c);

		for(i=0; i<N; i++){
			for(j=0; j<=W; j++){
				if(j < w[i]){
					dp[i+1][j][0] = dp[i][j][0];
					dp[i+1][j][1] = dp[i][j][1];
				}else{
					if(dp[i][j][0] > dp[i][j-w[i]][0] + v[i]){
						dp[i+1][j][0] = dp[i][j][0];
						dp[i+1][j][1] = dp[i][j][1];
					}else if(dp[i][j][0] == dp[i][j-w[i]][0] + v[i]){
						dp[i+1][j][0] = dp[i][j][0];
						dp[i+1][j][1] = min(dp[i][j][1], dp[i][j-w[i]][1] + w[i]);
					}else{
						dp[i+1][j][0] = dp[i][j-w[i]][0] + v[i];
						dp[i+1][j][1] = dp[i][j-w[i]][1] + w[i];
					}
				}
			}
		}
		printf("%d\n%d\n", dp[N][W][0], dp[N][W][1]);

	}

	return 0;
}

int min2(int a, int b){
	if(a > b)
		return b;
	return a;
}

Compiler output:
main.c: In function 'main':
main.c:49:65: error: implicit declaration of function 'min'; did you mean 'main'? [-Wimplicit-function-declaration]
   49 |                                                 dp[i+1][j][1] = min(dp[i][j][1], dp[i][j-w[i]][1] + w[i]);
      |                                                                 ^~~
      |                                                                 main
Language: C++

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

#define rep(i,n) for(int i=0; i < n;i++)

using namespace std;

int dp[1001][1001];

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}

int main()
{
	int count = 0;
	int W,n,ans;
	int w[1001],v[1001];

	while(cin >> W && W)
	{
		count++;
		memset(dp,0,sizeof(dp));
		cin >> n;
		rep(i,n)
		{
			string s;
			cin >> s;
			vector<string> _s = split(s,',');
			v[i] = atoi(_s[0].c_str());
			w[i] = atoi(_s[1].c_str());
		}

		for(int i=0;i< n ;i++)
		{
			for(int j = 0 ; j <= W; j++)
			{
				if(j < w[i])
				{
					dp[i+1][j] = dp[i][j];
				}
				else
				{
					dp[i+1][j] = max(dp[i][j],dp[i][j - w[i]] + v[i]);
				}
			}
		}
		for(int j=0;j <= W ; j++)
		{
			if(dp[n][j] == dp[n][W])
			{
				ans = j;
				break;
			}
		}
		cout << "Case " << count << endl;
		cout << dp[n][W] << endl << ans << endl;
	
	}

	return 0;
}

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

#include<iostream>
#include<algorithm>

int dp[1001][10001];
int v[1001], w[1001];

int main(){
	int W;

	int k = 1;
	while (std::cin >> W, W){
		int n;

		std::cin >> n;
		char a;
		for (int i = 0; i < n; i++)std::cin >> v[i] >> a >> w[i];

		memset(dp, -1, sizeof(dp));

		dp[1][0] = 0;
		dp[1][w[0]] = v[0];
		for (int i = 1; i < n; i++){
			for (int j = 0; j <= W; j++){

				if (dp[i][j] != -1){
					dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j]);
					if (j + w[i] <= W)dp[i + 1][j + w[i]] = std::max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
				}
			}
		}

		int max = 0, id = 0;
		for (int i = 1; i <= W; i++){
			if (max < dp[n][i])max = dp[n][i], id = i;
		}
		std::cout << "Case " << k << ":" << std::endl << max << std::endl << id << std::endl;

		k++;
	}

	return 0;
}

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

x=i=0
while(c=gets.to_i)>0
m=(1..gets.to_i).inject([0]*1e3){|s|v,w=gets.split(?,).map &:to_i;(0..c).map{|j|x=[s[j],w>j ?0:s[j-w]+v].max}}
puts "Case #{i+=1}:",x,m.index(x)
end

Compiler output:
a.cc:3:4: error: too many decimal points in number
    3 | m=(1..gets.to_i).inject([0]*1e3){|s|v,w=gets.split(?,).map &:to_i;(0..c).map{|j|x=[s[j],w>j ?0:s[j-w]+v].max}}
      |    ^~~~~~~~~~~~
a.cc:3:68: error: too many decimal points in number
    3 | m=(1..gets.to_i).inject([0]*1e3){|s|v,w=gets.split(?,).map &:to_i;(0..c).map{|j|x=[s[j],w>j ?0:s[j-w]+v].max}}
      |                                                                    ^~~~
a.cc:1:1: error: 'x' does not name a type
    1 | x=i=0
      | ^
a.cc:4:1: error: 'puts' does not name a type
    4 | puts "Case #{i+=1}:",x,m.index(x)
      | ^~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <map>
#include <cmath>
//#include <string>
//#include <sstream>
#include <iomanip>
//#include <complex>
#include <stdio.h>
//小数制度 	cout << fixed << setprecision(5) << tmp << endl;
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int dp[1010][1010];
int v[1010];
int w[1010];
int main(){
  int wei,n;
  int cnt = 1;
  while(cin >> wei,wei){
    cin >> n;
    REP(i,1010) REP(j,1010) dp[i][j] = 0;
    w[0]=0;v[0]=0;
    for(int i=0;i<n;i++){
      scanf("%d,%d",&v[i],&w[i]);
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<=awei;j++){
        if(j-w[i]<0) dp[i+1][j] = dp[i][j];
        else  dp[i+1][j]=max(dp[i][j+1],dp[i+1][j-w[i]]+v[i]);
      }
    }
    /*for(int i=0;i<n+1;i++){
      for(int j=0;j<wei+1;j++){
        cout << dp[i][j] << " ";//l<<endl;
      }
      cout << endl;
    }*/
    int maxv=0;
    int ans=-1;
    for(int i=0;i<wei+1;i++){
      if(maxv < dp[n][i]){
        maxv = dp[n][i];
        ans = i;
      }
    }
    cout << "Case " << cnt << ":" <<endl;
    cout << maxv << endl << ans << endl;
    cnt++;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:22: error: 'awei' was not declared in this scope; did you mean 'wei'?
   36 |       for(int j=0;j<=awei;j++){
      |                      ^~~~
      |                      wei
Language: C++

#include<iostream>
#define MAX_N 1001
#define MAX_W 1001
using namespace std;


int dp[MAX_N][MAX_W];
int n,W;
int w[MAX_N];
int v[MAX_N];

void solve(){
  memset(dp,0,sizeof(dp));
  cout<<"Case 1:"<<endl;
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      if(j>=w[i]){
	dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }else{
	dp[i+1][j]=dp[i][j];
      }
    }
  }
  cout << dp[n][W] << endl;
  int tmp=0;
  int weight;
  for(int i=0;i<=W;i++){
    if(dp[n][i]>tmp){
      tmp=dp[n][i];
      weight=i;
    }
  }
cout << weight << endl;
}

int main(){
  while(cin>>W,W){
    cin>>n;
    for(int i=0;i<n;i++){
      scanf("%d,%d",&v[i],&w[i]);
    }
    solve();
  }

  return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:13:3: error: 'memset' was not declared in this scope
   13 |   memset(dp,0,sizeof(dp));
      |   ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include<iostream>
  +++ |+#include <cstring>
    2 | #define MAX_N 1001
Language: C++

#include<iostream>
#include<algorithm>
#define MAX_N 1001
#define MAX_W 1001
using namespace std;


int dp[MAX_N][MAX_W];
int n,W;
int w[MAX_N];
int v[MAX_N];

void solve(){
  memset(dp,0,sizeof(dp));
  cout<<"Case 1:"<<endl;
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      if(j>=w[i]){
	dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }else{
	dp[i+1][j]=dp[i][j];
      }
    }
  }
  cout << dp[n][W] << endl;
  int tmp=0;
  int weight;
  for(int i=0;i<=W;i++){
    if(dp[n][i]>tmp){
      tmp=dp[n][i];
      weight=i;
    }
  }
cout << weight << endl;
}

int main(){
  while(cin>>W,W){
    cin>>n;
    for(int i=0;i<n;i++){
      scanf("%d,%d",&v[i],&w[i]);
    }
    solve();
  }

  return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:14:3: error: 'memset' was not declared in this scope
   14 |   memset(dp,0,sizeof(dp));
      |   ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<algorithm>
  +++ |+#include <cstring>
    3 | #define MAX_N 1001
Language: C++

#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;

int dp[2000][20000];    //dp[i][j]  i番目以前の物で、重さがj以下の時の価値
int W[2000],V[2000];

int w,n;

void solve(){
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<=w;j++){
            if(j-W[i]<0){
                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[0][w]<<endl;
    for(int i=w;i>=1;i--){
        if(dp[0][i]!=dp[0][i-1]){
            cout<<i<<endl;
            break;
        }
    }
}

int main(){
    int count=1;
    while(1){
        memset(dp,0,sizeof(dp));
    
        cin>>w>>n;
        if(w==0)break;
        char a;
        rep(i,n)cin>>V[i]>>a>>W[i];
    
        cout<<"Case "<<count<<":"<<endl;
        count++;
        solve();
    }
    return 0;
}

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

#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int min(int a,int b){
	if(a>=b)return b;
	else return a;
}

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void babbleSort(int *data,int n){
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(data[j]>=data[j-1]){
				swap(&data[j],&data[j-1]);
			}
		}
	}
}


using namespace std;

/*
cin.ignore();
	getline(cin,dataStr);
	data = new int[n];
	stringToInteger(&dataStr,data,n);
*/

void stringToInteger(string *str,int *data,int n){
	for(int i=1;i<=n;i++){
		int spaceN = str->find(' ',0);

		data[i] = atoi(str->substr(0,spaceN).c_str());
		str->erase(0,spaceN+1);
	}
}



int dp[1010];
//dp[i] i:重さ




int main(){


	int w,n;
	int cnt=1;
	while(1){
		cin>>w;
		if(w==0)break;

		cin>>n;

		for(int i=0;i<=w;i++){
			dp[i]=0;
		}
		int value,weight;
		for(int i=0;i<n;i++){
			scanf("%d,%d",&value,&weight);
			for(int j=w;j>=0;j--){
				if((j==0||dp[j]>0)&&((j+weight)<=w)){
					int tmp = dp[j]+value;
					dp[j+weight] = max(tmp,dp[j+weight]);
				//	cout<<j+weight<<" "<<dp[j+weight]<<endl;
				}
			}
		}

		int ans=0;
		int ansCnt=0;
		for(int i=0;i<=w;i++){
			if(ans<dp[i]){
				ans=dp[i];
				ansCnt=i;
			}
		}
		cout<<Case<<" "<<cnt<<":"<<endl;
		cout<<ans<<endl;
		cout<<ansCnt<<endl;
		cnt++;
	}



	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:98:23: error: 'Case' was not declared in this scope
   98 |                 cout<<Case<<" "<<cnt<<":"<<endl;
      |                       ^~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX_N 1000
#define MAX_W 1000

int N, W;
int v[MAX_N], w[MAX_N];
int memo[MAX_N][MAX_W];
int resW = 1e9;

int solve(int index, int weight){
  if(memo[index][weight] > 0) return memo[index][weight];

  int res;
  if(index == N) res = 0;
  else if(weight < w[index]) res = solve(index + 1, weight);
  else{
    res = max(solve(index + 1, weight), solve(index + 1, weight - w[index]) + v[index]);
  }
  return memo[index][weight] = res;
}

void askw(int ans, int weight, int index){
  if(ans == 0){
    if(weight < resW) resW = weight;
  }
  if(index == N) return;
  if(ans - v[index] >= 0){
    askw(ans - v[index], weight + w[index], index + 1);
    askw(ans, weight, index + 1);
  }
}

int main(void){
  int cnt = 0, ans;
  while(cin >> W, W){
    cnt++;
    cin >> N;
    for(int i = 0; i < N; i++){
      scanf("%d,%d", &v[i], &w[i]);
    }
    memset(memo, -1, sizeof(memo));
    ans = solve(0, W); askw(ans, 0, 0);
    cout << "Case " << cnt << ":" << endl;
    cout << ans << endl;
    cout << resW << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:5: error: 'memset' was not declared in this scope
   44 |     memset(memo, -1, sizeof(memo));
      |     ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <algorithm>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int w[1000],v[1000];
int W,N;
int memo[1001][1001];
int func(int i,j){
    if(memo[i][j]>=0)return memo[i][j];
    
    int res;
    if(i==N)res=0;
    else if(j-w[i]<0)res=func(i+1,j);
    else res=max(func(i+1,j),func(i+1,j-w[i])+v[i]);
    
    return memo[i][j]=res;
}
int main(){
    int cnt=0;
    while(cin>>W,W){
        cin>>N;
        cnt++;
        for(int i=0;i<N;i++)(cin>>v[i]).ignore()>>w[i];
        fill(memo[0],memo[0]+1001*1001,-1);
        memo[0][0]=0;
        func(0,W);
        
        for(int i=W;i>=0;i--){
            if(memo[0][i]==-1)continue;
            if(memo[0][i]>memo[0][i-1]){
                cout<<"Case "<<cnt<<":"<<endl;
                cout<<memo[0][i]<<endl<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

Compiler output:
a.cc:8:16: error: 'j' has not been declared
    8 | int func(int i,j){
      |                ^
a.cc: In function 'int func(int, int)':
a.cc:9:16: error: 'j' was not declared in this scope
    9 |     if(memo[i][j]>=0)return memo[i][j];
      |                ^
a.cc:13:13: error: 'j' was not declared in this scope
   13 |     else if(j-w[i]<0)res=func(i+1,j);
      |             ^
a.cc:16:20: error: 'j' was not declared in this scope
   16 |     return memo[i][j]=res;
      |                    ^
Language: C++

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){

	int w,n,cnt=1;
	int dp[1006][10005],V[1001],W[1001];
	while(cin>>w,w){
		cin>>n;
		for(int i=0;i<n;i++)scanf("%d,%d",&V[i],&W[i]);
		int cnt=0;for(int i=0;i<n;i++)cnt+=W[i];
		if(cnt>=10000)for(;;);
		for(int i=1;i<=n;i++){
			for(int j=0;j<=w;j++){
				if(j-W[i-1]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-W[i-1]]+V[i-1]);
				if(dp[i
			}
		}
		int tmp=w;
		for(int i=w;i>=0;i--)if(dp[n][i]==dp[n][w])tmp=i;
		cout<<"Case "<<cnt<<":"<<endl<<dp[n][w]<<endl<<tmp<<endl;
		cnt++;
		for(int i=0;i<1001;i++)for(int j=0;j<=1000;j++)V[i]=W[i]=0;
		for(int i=0;i<1006;i++)fill(dp[i],dp[i+10005],0);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:40: error: expected ']' before '}' token
   17 |                                 if(dp[i
      |                                        ^
      |                                        ]
   18 |                         }
      |                         ~               
a.cc:17:40: error: expected ')' before '}' token
   17 |                                 if(dp[i
      |                                   ~    ^
      |                                        )
   18 |                         }
      |                         ~               
a.cc:18:25: error: expected primary-expression before '}' token
   18 |                         }
      |                         ^
Language: C++

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){

	int w,n,cnt=1;
	int dp[1006][10005],V[1001],W[1001];
	while(cin>>w,w){
		cin>>n;
		for(int i=0;i<n;i++)scanf("%d,%d",&V[i],&W[i]);
		int cnt=0;for(int i=0;i<n;i++)cnt+=W[i];
		if(cnt>=10000)for(;;);
		for(int i=1;i<=n;i++){
			for(int j=0;j<=w;j++){
				if(j-W[i-1]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-W[i-1]]+V[i-1]);
				if(dp[i
			}
		}
		int tmp=w;
		for(int i=w;i>=0;i--)if(dp[n][i]==dp[n][w])tmp=i;
		cout<<"Case "<<cnt<<":"<<endl<<dp[n][w]<<endl<<tmp<<endl;
		cnt++;
		for(int i=0;i<1001;i++)for(int j=0;j<=1000;j++)V[i]=W[i]=0;
		for(int i=0;i<1006;i++)fill(dp[i],dp[i]+10005,0);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:40: error: expected ']' before '}' token
   17 |                                 if(dp[i
      |                                        ^
      |                                        ]
   18 |                         }
      |                         ~               
a.cc:17:40: error: expected ')' before '}' token
   17 |                                 if(dp[i
      |                                   ~    ^
      |                                        )
   18 |                         }
      |                         ~               
a.cc:18:25: error: expected primary-expression before '}' token
   18 |                         }
      |                         ^
Language: C++

#include<iostream>
using namespace std;
int main(){
  int dp[1001][1001];
  int n,W;
  int v[1000],w[1000];
  int num=0;
  while(cin>> W,W){
    num++;
    cin>> n;
    for(int i=0;i<w+1;i++){
      dp[0][i]=0;
    }

    for(int i=0;i<n;i++){
      char c;
      cin>> v[i]>> c>> w[i];
    }

    for(int i=1;i<=n;i++){
      for(int 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],dp[i-1][j-w[i-1]]+v[i-1]);
	}
      }
    }

    int mv=0,mw;
    for(int j=0;j<=W;j++){
      if(mv<dp[n][j]){
	mv=dp[n][j];
	mw=j;
      }
    }
    /*for(int i=0;i<=n;i++){
      for(int j=0;j<=W;j++){
	cout<< dp[i][j];
      }
      cout<< endl<< endl;
    }
    */
    cout<< "Case "<< num<< ":"<< endl;
    cout<< mv<< endl;
    cout<< mw<< endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:18: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   11 |     for(int i=0;i<w+1;i++){
      |                 ~^~~~
Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int w,n;
int kati[1111],omo[1111];
int memo[1111][1111];
int main(){
  int cas=0;
  int anskati=0;
  int ansomo;
  int w,n;
  int kati[1111],omo[1111];
  int memo[1111][1111];
  while(1){
    cas++;
    cin>>w;
    if(w==0) break;
    cin>>n;
    for(int i=0;i<=W;i++){
      memo[0][i]=0;
    }
    for(int i=0;i<n;i++){
      scanf("%d,%d",&kati[i],&omo[i]);
    }
    cout<<"Case "<<cas<<':'<<endl;
    
    for(int i=1;i<=n;i++){
      for(int j=1;j<=w;j++){
	if(j<omo[i-1]){
	  memo[i][j]=memo[i-1][j];
	}else{
	  memo[i][j]=max(memo[i-1][j],memo[i-1][j-omo[i-1]]+kati[i-1]);
	}
      }
    }
    for(int i=0;i<=w;i++){
      if(memo[n][i]>anskati){
	anskati=memo[n][i];
	ansomo=i;
      }
    }
    cout<<anskati<<endl;
    cout<<ansomo<<endl;
    
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:20: error: 'W' was not declared in this scope
   20 |     for(int i=0;i<=W;i++){
      |                    ^
Language: C++

#include <iostream>
#include <cstdio>

using namespace std;

ll value[1000], weight[1000];
ll dp[1001][1001]; // dp[?¬?????????????][??????] = ?????§??????

int main() {
	int W;
	int c = 1;
	while ( cin >> W, W ) {
		int N; cin >> N;
		for (int i = 0; i < N; ++i) scanf("%d,%d", &value[i], &weight[i]);

		fill(&dp[0][0], &dp[0][0]+1001*1001, 0);

		for (int i = 0; i < N; ++i) {
			for (int w = 0; w <= W; ++w) {
				dp[i+1][w] = max(dp[i+1][w], dp[i][w]);
				if (w + weight[i] <= W) {
					dp[i+1][w+weight[i]] = max(dp[i+1][w+weight[i]], dp[i][w]+value[i]);
				}
			}
		}
		ll av = 0, aw = 0;
		for (int w = 0; w < W; ++w) {
			if (dp[N][w] > av) {
				av = dp[N][w];
				aw = w;
			}
		}
		printf("Case %d:\n", c++);
		printf("%d\n", av);
		printf("%d\n", aw);
	}
}

Compiler output:
a.cc:6:1: error: 'll' does not name a type
    6 | ll value[1000], weight[1000];
      | ^~
a.cc:7:1: error: 'll' does not name a type
    7 | ll dp[1001][1001]; // dp[?¬?????????????][??????] = ?????§??????
      | ^~
a.cc: In function 'int main()':
a.cc:14:61: error: 'value' was not declared in this scope
   14 |                 for (int i = 0; i < N; ++i) scanf("%d,%d", &value[i], &weight[i]);
      |                                                             ^~~~~
a.cc:14:72: error: 'weight' was not declared in this scope
   14 |                 for (int i = 0; i < N; ++i) scanf("%d,%d", &value[i], &weight[i]);
      |                                                                        ^~~~~~
a.cc:16:23: error: 'dp' was not declared in this scope
   16 |                 fill(&dp[0][0], &dp[0][0]+1001*1001, 0);
      |                       ^~
a.cc:21:41: error: 'weight' was not declared in this scope
   21 |                                 if (w + weight[i] <= W) {
      |                                         ^~~~~~
a.cc:22:99: error: 'value' was not declared in this scope
   22 |                                         dp[i+1][w+weight[i]] = max(dp[i+1][w+weight[i]], dp[i][w]+value[i]);
      |                                                                                                   ^~~~~
a.cc:26:17: error: 'll' was not declared in this scope
   26 |                 ll av = 0, aw = 0;
      |                 ^~
a.cc:28:40: error: 'av' was not declared in this scope
   28 |                         if (dp[N][w] > av) {
      |                                        ^~
a.cc:30:33: error: 'aw' was not declared in this scope; did you mean 'w'?
   30 |                                 aw = w;
      |                                 ^~
      |                                 w
a.cc:34:32: error: 'av' was not declared in this scope
   34 |                 printf("%d\n", av);
      |                                ^~
a.cc:35:32: error: 'aw' was not declared in this scope
   35 |                 printf("%d\n", aw);
      |                                ^~
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
using namespace std;

struct Treasure{
	int Weight;
	int Worth;
};
vector<int> TempMaxWorth;

int GetMaxWorth(const int MaxWeight,vector<Treasure> nowTreasureCollection,vector<Treasure>::iterator& nowIterator,const vector<Treasure>& AllTreasureCollection){
	 vector<Treasure>::iterator rootIterator(nowIterator);
	for (; nowIterator!=AllTreasureCollection.end(); ++nowIterator){
		nowTreasureCollection.push_back(*(nowIterator));
		const int NowWorth = accumulate(nowTreasureCollection.cbegin(),
			nowTreasureCollection.cend(),
			0,
			[](const int q, const Treasure& p){return q + p.Worth; }
		);
		const int NowWeight = accumulate(nowTreasureCollection.cbegin(),
			nowTreasureCollection.cend(),
			0,
			[](const int q, const Treasure& p){return q + p.Weight; });
		if (NowWeight <= MaxWeight&&NowWorth > TempMaxWorth[NowWeight]){
			TempMaxWorth[NowWeight] = NowWorth;
			replace_if(TempMaxWorth.begin() + NowWeight, TempMaxWorth.end(), [=](int n){return NowWorth > n; }, NowWorth);
			if((++nowIterator)!=AllTreasureCollection.end())GetMaxWorth(MaxWeight, nowTreasureCollection, nowIterator,AllTreasureCollection);
			nowIterator--;
		}
		nowTreasureCollection.pop_back();
	}
	((nowIterator)) = (rootIterator);
	return 0;
}

int main(){
	int MaxWeight;
	int TreasureNum;
	for (int i = 1; cin >> MaxWeight;++i){
		if (MaxWeight == 0)return 0;
		cin  >> TreasureNum;
		TempMaxWorth.resize(MaxWeight + 1);
		fill(TempMaxWorth.begin(), TempMaxWorth.end(), 0);
		vector<Treasure> AllTreasureCollection;
		for (int j = 0; j < TreasureNum; ++j){
			Treasure T;
			cin >> T.Worth;
			cin.get();
			cin >> T.Weight;
			AllTreasureCollection.push_back(T);
		}	
		vector<Treasure> NowTreasureCollection = {};
		GetMaxWorth(MaxWeight, NowTreasureCollection, AllTreasureCollection.begin(), AllTreasureCollection);
		cout << "Case " << i << " :" << endl << TempMaxWorth[MaxWeight] << endl << find(TempMaxWorth.cbegin(), TempMaxWorth.cend(), TempMaxWorth[MaxWeight]) - TempMaxWorth.cbegin() << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:90: error: cannot bind non-const lvalue reference of type 'std::vector<Treasure>::iterator&' to an rvalue of type 'std::vector<Treasure>::iterator'
   56 |                 GetMaxWorth(MaxWeight, NowTreasureCollection, AllTreasureCollection.begin(), AllTreasureCollection);
      |                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
a.cc:14:104: note:   initializing argument 3 of 'int GetMaxWorth(int, std::vector<Treasure>, std::vector<Treasure>::iterator&, const std::vector<Treasure>&)'
   14 | int GetMaxWorth(const int MaxWeight,vector<Treasure> nowTreasureCollection,vector<Treasure>::iterator& nowIterator,const vector<Treasure>& AllTreasureCollection){
      |                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
Language: C++

#include <cstdio>
using namespace std;

struct pre{ int v, w; };

int max(int a, int b){
	return (a > b) a : b;
}

int main(){
	const int MAX_N = 1000, MAX_W = 1000;
	int N, W;
	pre dat[MAX_N];
	int dp[MAX_N][MAX_W + 1];
	int p;
	
	for(int n = 1;; n++){
		scanf("%d", &W);
		if(W == 0) break;
		scanf("%d", &N);
		for(int i = 0; i < N; i++) scanf("%d,%d", &dat[i].v, &dat[i].w);
		
		for(int i = 0; i < MAX_N; i++){
			for(int j = 0; j < MAX_W; j++){
				dp[i][j] = 0;
			}
		}
		
		for(int i = dat[0].w; i <= W; i++) dp[0][i] = dat[0].v;
		for(int i = 1; i < N; i++){
			for(int j = 0; j <= W; j++){
				dp[i][j] = max((dat[i].w <= j)? dp[i - 1][j - dat[i].w] + dat[i].v : 0, dp[i - 1][j]);
			}
		}
		
		for(int i = 0; i <= W; i++){
			if(dp[N - 1][i] == dp[N - 1][W]){
				printf("Case %d:\n%d\n%d\n", n, dp[N - 1][W], i);
				break;
			}
		}
	}
	
	return 0;
}

Compiler output:
a.cc: In function 'int max(int, int)':
a.cc:7:23: error: expected ';' before 'a'
    7 |         return (a > b) a : b;
      |                       ^~
      |                       ;
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int dp[1500][1500];

int solve(int i,int j){
  if(dp[i][j] != -1) return dp[i][j];

  int hoge;

  if(i == n) hoge = 0;

  else if(j < w[i]) hoge = solve(i+1, j);

  else hoge =  max(solve(i+1, j) , solve(i+1 , j - w[i]) + v[i]);

  return dp[i][j] = hoge;

}

int main(){

  while(1){
	int h;
	cin >> h;
	if(h == 0) break;

	int n;
	cin >> n;

	int v[1500],w[1500];

	REP(i,n){
	  cin >> v[i]>> w[i];
	}

	REP(i,1500) REP(j,1500) dp[i][j] = -1;

	cout << solve(0,h) << endl;

  }
}

Compiler output:
a.cc: In function 'int solve(int, int)':
a.cc:35:11: error: 'n' was not declared in this scope
   35 |   if(i == n) hoge = 0;
      |           ^
a.cc:37:15: error: 'w' was not declared in this scope
   37 |   else if(j < w[i]) hoge = solve(i+1, j);
      |               ^
a.cc:39:60: error: 'v' was not declared in this scope
   39 |   else hoge =  max(solve(i+1, j) , solve(i+1 , j - w[i]) + v[i]);
      |                                                            ^
Language: C++

#include<iostream>
#include<vector>
using namespace std;

int main(){
    int w,n,va,we;
    int dp[1000];
    char c;
    vector<pair<int,int> >vec;
    
    while(cin>>w>>n,w){
        for(int i=0;i<n;i++){
            cin>>va>>c>>we;
            vec.push_back(make_pair(va, we));
        }
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;i++){
            int tv=vec[i].first, tw=vec[i].second;
            for(int j=w;j>=0;j--){
                if(tw==j)continue;
                if(tw+j<=w){
                    dp[tw+j]=max(dp[tw+j],dp[j]+tv);
                }
            }
        }
        int aw=0,av=0;
        for(int i=0;i<=w;i++) {
            if(dp[i]>av){
                aw=i;
                av=dp[i];
            }
        }
        cout<<av<<endl<<aw<<endl;
        vec.clear();
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:9: error: 'memset' was not declared in this scope
   16 |         memset(dp,0,sizeof(dp));
      |         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<vector>
  +++ |+#include <cstring>
    3 | using namespace std;
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>

#define MAX_N 1001
#define MAX_W 10001

int dp[MAX_W][MAX_N], W, N, value[MAX_N], w[MAX_N];

int main(){
    int Case = 0;
    
    while(true){
        for(int i = 0; i < MAX_N; ++i)
            memset(dp[i], 0, MAX_W);
        //initialize
        
        ++Case;
        scanf("%d%d", &W, &N);
        if(!W)
            break;
        for(int i = 0; i < N; ++i)
            scanf("%d,%d", &value[i], &w[i]);
        //input
        
        for(int i = 0; i < N; ++i){
            for(int j = 0; j <= W; ++j){
                if(j < w[i])
                    dp[i + 1][j] = dp[i][j];
                else
                    dp[i + 1][j] = std::max(dp[i][j - w[i]] + value[i], dp[i][j]);
            }
        }
        //solve
        
        int ans = dp[N][W];
        
        printf("Case %d:\n%d\n", Case, ans);
        
        int i = 0;
        while(true){
            if(ans != dp[N][W - i]){
                printf("%d\n", W - i + 1);
                break;
            }
            ++i;
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:13: error: 'memset' was not declared in this scope
   15 |             memset(dp[i], 0, MAX_W);
      |             ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <algorithm>
  +++ |+#include <cstring>
    4 |
Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;

int main(){
	int W,N,cou=0;
	int tr[1001],we[1001];
	while(cin >> W , W){
		cou++;
		cin >> N;
		for(int i=1;i<=N;i++){
			scanf("%d,%d",&tr[i],&we[i]);
		}

		P dp[1010][1001];
		for(int i=0;i<=N;i++){
			for(int j=0;j<=N;j++){
				dp[i][j] = P(0,0);
			}
		}
		dp[0][0] = P(0,0);
		for(int i=1;i<=N;i++){
			dp[i][0] = P(0,0);
			for(int j=0;j<i;j++){
				if(dp[i-1][j].second+we[i] <= W){
					P p;
					p = P(dp[i-1][j].first+tr[i],dp[i-1][j].second+we[i]);
					if(p.first == dp[i-1][j+1].first){
						if(p.second < dp[i-1][j+1].second) dp[i][j+1] = p;
						else dp[i][j+1] = dp[i-1][j+1];
					}
					else if(p.first > dp[i-1][j+1].first){
						dp[i][j+1] = p;
					}
					else dp[i][j+1] = dp[i-1][j+1];
				}
				else dp[i][j+1] = dp[i-1][j+1];
			}
		}
		int ans1=0,ans2=0;
		for(int i=0;i<=N;i++){
			if(dp[N][i].first == ans1){
				if(dp[N][i].second < ans2) ans2 = dp[N][i].second;
			}
			else if(dp[N][i].first > ans1){
				ans1 = dp[N][i].first;
				ans2 = dp[N][i].second;
			}
		}

		cout << "Case " << cou << ":" << endl;
		cout << ans1 << endl;
		cout << ans2 << endl;
	}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:10: error: expected '}' at end of input
   57 |         }
      |          ^
a.cc:8:11: note: to match this '{'
    8 | int main(){
      |           ^
Language: C++

#include<iostream>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define max_n 1000
#define max_w 10000
using namespace std;

int N,W;
int dp[max_n][max_w];
int dw[max_n][max_w];
int w[max_n],v[max_n];

int rec(int i,int j){
	int res;
	if(dp[i][j]!=-1)return dp[i][j];
	if(i==N){
		res=0;
		dw[i][j]=0;
	}else if(j<w[i]){
		res=rec(i+1,j);
		dw[i][j]=dw[i+1][j];
	}else{
		int r1=rec(i+1,j);
		int r2=rec(i+1,j-w[i])+v[i];
		if(r1>r2){
			res=r1;
			dw[i][j]=dw[i+1][j];
		}else if(r2>r1){
			res=r2;
			dw[i][j]=dw[i+1][j-w[i]]+w[i];
		}else{
			if(dw[i+1][j]>(dw[i+1][j-w[i]]+w[i])){
				res=r2;
				dw[i][j]=dw[i+1][j-w[i]]+w[i];
			}else{
				res=r1;
				dw[i][j]=dw[i+1][j];
			}
		}
	}
	return dp[i][j]=res;
}

int main(){
	int p=1;
	while(cin>>W,W){
		cin>>N;
		rep(i,N){
			scanf("%d,%d",&v[i],&w[i]);
		}
		memset(dp,-1,sizeof(dp));
		memset(dw,-1,sizeof(dw));
		cout<<"Case "<<p<<":"<<endl;
		cout<<rec(0,W)<<endl;
		cout<<dw[0][W]<<endl;
		p++;
		/*cout<<"value="<<rec(0,W)<<" cost="<<dw[0][W]<<endl;//????????§??????????????????
		cout<<"cost="<<dw[0][W]<<endl;*/
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:17: error: 'memset' was not declared in this scope
   52 |                 memset(dp,-1,sizeof(dp));
      |                 ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<cstdio>
  +++ |+#include <cstring>
    3 | #define loop(i,a,b) for(int i=a;i<b;i++)
Language: C++

# include <iostream>
# include <algorithm>

const int MAX_N = 1001;
const int MAX_W = 1001;

int t;
int n, W;
int v[MAX_N], w[MAX_N];

int dp[MAX_N][MAX_W];

int main() {
	while (1) {
		std::cin >> W;
		if (w == 0)
			break;
		std::cin >> n;
		char ch;
		for (int i = 1; i <= n; ++i)
			std::cin >> v[i] >> ch >> w[i];
		std::memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= n; ++i) {
			for (int j = 0; j <= W; ++j) {
				if (w[i] > j)
					continue;
				dp[i][j] = std::max(dp[i - 1][j - w[i]] + v[i], dp[i][j]);
			}
		}
		int max = 0, maxv;
		for (int i = 0; i <= W; ++i) {
			if (max < dp[n][i]) {
				maxv = i;
				max = dp[n][i];
			}
		}
		++t;
		std::cout << "Case " << t << ':' << std::endl;
		std::cout << max << std::endl << maxv << std::endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:22: error: 'memset' is not a member of 'std'; did you mean 'wmemset'?
   22 |                 std::memset(dp, 0, sizeof(dp));
      |                      ^~~~~~
      |                      wmemset
Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)
 
template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
 
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
 
int W, N;
int tres[1001];
int weig[1001];
int maxW, maxV;
int dp[1001][1001];
 
void dfs(int weight, int value, int index){
	if(can[index] < maxV)return;
    if(weight > W)return;
    if(dp[weight][index]>value)return;
    dp[weight][index] = value;
    if(index == N){
        if(maxV < value){
            maxW = weight;
            maxV = value;
        }else if(maxV == value){
            if(maxW > weight){
                maxW = weight;
                maxV = value;
            }
        }
        return;
    }
    if(dp[weight][index+1]<value)dfs(weight, value, index+1);
    if(weight+weig[index] > W)return;
    if(dp[weight+weig[index]][index+1]<value+tres[index])dfs(weight+weig[index], value+tres[index], index+1);
}
 
 
int main(void){
    int cnt = 0;
    while(cin >> W, W){
        cnt++;
        cin >> N;
        maxW = 0;
        maxV = 0;
        // fill_n(tres, 1001, 0);
        // fill_n(weig, 1001, 0);
        fill_n(*dp, 1001*1001, -1);
 
        rep(i,N){
            int n, w;
            scanf("%d,%d", &n, & w);
            tres[i] = n;
            weig[i] = w;
            if(i==0)can[i]=tres[i];
            else can[i] = can[i-1]+tres[i];
        }
 
        dfs(0,0,0);
        cout << "Case " << cnt << ":" << endl;
        cout << maxV << endl << maxW << endl;
    }
 
    return 0;
}
 
 
 
int StrToInt(string s){
    stringstream ss;
    ss << s;
    int val;
    ss >> val;
    return val;
}
string IntToStr(int i){
    stringstream ss;
    ss << i;
    return ss.str();
}

Compiler output:
a.cc: In function 'void dfs(int, int, int)':
a.cc:42:12: error: 'can' was not declared in this scope; did you mean 'tan'?
   42 |         if(can[index] < maxV)return;
      |            ^~~
      |            tan
a.cc: In function 'int main()':
a.cc:80:21: error: 'can' was not declared in this scope; did you mean 'tan'?
   80 |             if(i==0)can[i]=tres[i];
      |                     ^~~
      |                     tan
a.cc:81:18: error: 'can' was not declared in this scope; did you mean 'tan'?
   81 |             else can[i] = can[i-1]+tres[i];
      |                  ^~~
      |                  tan
Language: C++

#include <iostream>
#include <cstdio>

#define MAX(A, B) (A) > (B) ? (A) : (B)

using namespace std;

int dp[1001][1001];
int w[1000], v[1000];

int main() {
	int N, W;
	int c = 0;
	memset(dp, 0, sizeof dp);
	while (cin >> W, W) {
		cin >> N;
		for (int i = 0; i < N; i++) {
			scanf("%d,%d", &v[i], &w[i]);
		}
		for (int i = 0; i < N; i++) {
			for (int j = W; j >= 0; j--) {
				if (j >= w[i])
					dp[i+1][j] = MAX(dp[i][j], dp[i][j-w[i]]+v[i]);
				else
					dp[i+1][j] = dp[i][j];
			}
		}
		while (dp[N][W] == dp[N][W - 1]) W--;
		cout << "Case " << ++c << ':' << endl;
		cout << dp[N][W] << endl << W << endl;;
	}

	return 0;
}

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

#include<bits/stdc++.h>
using namespace std;
int dp[1001][1001],wait[1001],value[1001];
void Initialization()
{
    for(int i=0;i<1001;i++)for(int j=0;j<1001;j++)dp[i][j]=-1;
}
int power(int n)
{
    int num=1;
    for(int i=1;i<=n;i++)num*=10;
    return num;
}
int serch(int i,int j,int n)
{
    int num;
    if(dp[i][j]>-1)return dp[i][j];
    else if(i==n)num=0;
    else if(j<wait[i])num=serch(i+1,j,n);
    else num=max(serch(i+1,j,n),serch(i+1,j-wait[i],n)+value[i]);
    return dp[i][j]=num;
}
int wserch(int i,int va,int ser,int n,int w)
{
    int num;
    if(i==n)num=w;
    else if(ser<va+value[i])num=wserch(i+1,va,ser,n,w);
    else if(ser==va+value[i])num=wait[i];
    else num=min(wserch(i+1,va,ser,n,w),wserch(i+1,va+value[i],ser,n,w)+wait[i]);
    return num;
}
int main()
{
    int n,w,point,num=1,wai,wa;
    string str;
    while(cin>>w&&w!=0){
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>str;
            value[i]=0;wait[i]=0;
            for(int j=0;;j++){
                if(str[j]==','){
                    for(int k=0;k<j;k++)value[i]+=power(j-k-1)*(str[k]-'0');
                    point=j;
                }
                if(str[j]=='\0'){
                    for(int k=point+1;k<j;k++)wait[i]+=power(j-k-1)*(str[k]-'0');
                    break;
                }
            }
        }
        Initialization();
        point=serch(0,w,n);
        wai=w;
        for(int i=0;i<n;i++){
            if(value[i]<point){
                wa=wserch(i+1,value[i],point,n,w)+wait[i];
                if(wa<wai)wai=wa;
            }
            else if(value[i]==point&&wai>wa)wai=wa;
        }
        cout<<"Case "<<num<<":\n"<<point<<endl<<wai<<endl;
        now++;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:63:9: error: 'now' was not declared in this scope; did you mean 'pow'?
   63 |         now++;
      |         ^~~
      |         pow