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

#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define M_N 1000
#define M_W 10000

typedef pair<int, int> ii; //?????????, ?????????

int W, N;
int v[M_N], w[M_N];
int dp[M_N + 1][M_W + 1][2];

//?????????j??\?????¶??????i????????\????????????????????????
ii dfs(int i, int j) {
	if (dp[i][j][0] != -1)
		return ii(
			dp[i][j][0],
			dp[i][j][1]
		);

	if (i == N) {
		//?????°??¶?????????????????¨???
		return ii(
			dp[i][j][0] = 0,
			dp[i][j][1] = 0
		);
	}
	else if (j < w[i]) {
		//i??????????????????????????¶?????§??\??????????????¨???
		return ii(
			dp[i][j][0] = dfs(i + 1, j).first,
			dp[i][j][1] = dfs(i + 1, j).second
		);
	}
	else {
		//???????????\???????????\??????????????§?????????????????????????????§??¨?????????
		int a = dfs(i + 1, j).first,
			b = dfs(i + 1, j - w[i]).first + v[i];
		if (a > b)
			return ii(
				dp[i][j][0] = a,
				dp[i][j][1] = dfs(i + 1, j).second
			);
		else
			return ii(
				dp[i][j][0] = b,
				dp[i][j][1] = dfs(i + 1, j - w[i]).second + w[i]
			);

	}
}

int main() {
	for (int h = 0; cin >> W, W; h++) {
		cin >> N;
		memset(dp, -1, sizeof(dp));
		for (int i = 0; i < N; i++) {
			char c;
			cin >> v[i] >> c >> w[i];
		}
		cout << "Case " << h << ":" << endl;
		cout << dfs(0, W).first << endl;
		cout << dfs(0, W).second << endl;
	}
	return 0;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

int caseId = 1;

void solve42(int W) {
    cout << "Case " << caseId << ":" << endl;
    int N;
    cin >> N;
    REP(i,N) {
        int dp[1001] = {0}; // dp[i]: maxvalue under weight i
        int v, w;
        scanf("%d,%d", &v, &w);
        for(int j = W; j >= w; j--) {
            dp[j] = max(dp[j], dp[j-w] + v);
        }
    }
    int value = 0, weight = 0;
    REP(i,W) {
        if (value < dp[i]) {
            value = dp[i];
            weight = i;
        }
    }
    cout << value << endl << weight << endl;
}

int main() {
    int W;
    while (cin >> W, W) {
        solve42(W);
        caseId++;
    }
    return 0;
}

Compiler output:
a.cc: In function 'void solve42(int)':
a.cc:30:21: error: 'dp' was not declared in this scope
   30 |         if (value < dp[i]) {
      |                     ^~
Language: C++

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

#define scanf scanf_s

int a[10001] = { 0 };
int b[10001] = { 0 };
int w, n, mv, mw;
void solve(int W, int f, int sum) {
	f = min(f, n) + 1;
	for (int i = f; i < n; i++) {
		if (W - b[i] < 1) {
			mw = max(w - W, mw);
			mv = max(sum, mv);
			return;
		}
		solve(W - b[i], f, sum + a[i]);
	}
}

int main() {
	int u = 0;
	while (cin >> w) {
		if (w == 0) break;
		cin >> n;

		mv = mw = 0; u++;
		for (int i = 0; i < n; i++) {
			scanf("%d,%d", &a[i], &b[i]);
		}

		solve(w, -1, 0);
		printf("Case %d:\n%d\n%d\n", u, mv, mw);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:15: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
    6 | #define scanf scanf_s
      |               ^~~~~~~
a.cc:31:25: note: in expansion of macro 'scanf'
   31 |                         scanf("%d,%d", &a[i], &b[i]);
      |                         ^~~~~
Language: C++

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

class treasure
{
public:
int value, weight;
bool have;
};

treasure tre[1000];
int N,W, VALUE = 0, WEIGHT = 999999;


void calcu()
{
	int sum_v = 0, sum_w = 0;
	for (int i = 0; i < N; i++)
	{
		if (tre[i].have == true)
		{
			sum_v += tre[i].value;
			sum_w += tre[i].weight;
		}
	}
	if (sum_v>VALUE)
	{
		WEIGHT = sum_w;
		VALUE = sum_v;
	}
	else if(sum_v==VALUE &&  WEIGHT>sum_w)
	{
		 WEIGHT = sum_w;
	}
}

void function(int n, int w)//0,W
{
	if (n >= N)	
	{
		calcu();
		//cout << VALUE << "," << WEIGHT << endl;
	}
	else if (tre[n].weight > w)	
	{
		tre[n].have=false;
		function(n + 1, w);
	}
	else
	{
		tre[n].have = true;	  
		function(n + 1, w - tre[n].weight);
		tre[n].have = false;   
		function(n + 1, w);
	}
}

int main()
{
	int W;
	for (int count = 1; cin >> W, W != 0; count++)
	{
		VALUE = 0;
		WEIGHT = 999999;
		cin >> N;
		for (int i = 0; i < N; i++)
		{
			scanf_s("%d,%d", &tre[i].value, &tre[i].weight);
		}
		function(0,W);
		cout << "case " << count << ":" << endl;
		cout << VALUE << endl;
		cout << WEIGHT << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:71:25: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   71 |                         scanf_s("%d,%d", &tre[i].value, &tre[i].weight);
      |                         ^~~~~~~
      |                         scanf
Language: C++


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;

class treasure
{
public:
int value, weight;
bool have;
};

treasure tre[1000];
int N,W, VALUE = 0, WEIGHT = 999999;

void calcu()
{
	int sum_v = 0, sum_w = 0;
	for (int i = 0; i < N; i++)
	{
		if (tre[i].have == true)
		{
			sum_v += tre[i].value;
			sum_w += tre[i].weight;
		}
	}
	if (sum_v>VALUE)
	{
		WEIGHT = sum_w;
		VALUE = sum_v;
	}
	else if(sum_v==VALUE &&  WEIGHT>sum_w)
	{
		 WEIGHT = sum_w;
	}
}

void function(int n, int w)//0,W
{
	if (n >= N)	  
	{
		calcu();
	}
	else if (tre[n].weight > w)	 
	{
		tre[n].have=false;
		function(n + 1, w);
	}
	else
	{
		tre[n].have = true;
		function(n + 1, w - tre[n].weight);
		tre[n].have = false;
		function(n + 1, w);
	}
}

int main()
{
	int W;
	for (int count = 1; cin >> W, W != 0; count++)
	{
		VALUE = 0;
		WEIGHT = 999999;
		cin >> N;
		for (int i = 0; i < N; i++)
		{
			scanf_s("%d,%d", &tre[i].value, &tre[i].weight);
		}
		function(0,W);
		cout << "case " << count << ":" << endl;
		cout << VALUE << endl;
		cout << WEIGHT << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:71:25: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   71 |                         scanf_s("%d,%d", &tre[i].value, &tre[i].weight);
      |                         ^~~~~~~
      |                         scanf
Language: C++

#include <iostream>
#include <array>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
#define out(s) cout << (s) << endl;

int dp[1001][1001];

int main()
{
	int W, N, cnt = 1;
	cin >> W;
	while (W!=0)
	{
		cin >> N;
		memset(dp, -1, sizeof(dp));
		dp[0][0] = 0;
		for (size_t i = 0; i < N; i++)
		{
			int vi, wi;
			scanf("%d,%d", &vi, &wi);
			for (size_t n = 0; n <= W; n++)
			{
				if (dp[i][n] != -1) {
					dp[i + 1][n] = max(dp[i][n], dp[i + 1][n]);
					dp[i + 1][n + wi] = max(dp[i][n] + vi, dp[i][n]);
				}
			}
		}
		int dp_max = dp[N][W];
		int index = W;
		for (size_t i = W; i > 0; i--)
		{
			if (dp_max == dp[N][i])index = i;
		}
		cout << "Case " << cnt << ":" << endl << dp_max << endl << index << endl;
		cin >> W;
		cnt++;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:17: error: 'memset' was not declared in this scope
   19 |                 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 <vector>
  +++ |+#include <cstring>
    6 | using namespace std;
Language: C++

#include <iostream>
#include <array>
#include <string>
#include <tuple>
#include <vector>
#include<stdio.h>
#include<string.h>
using namespace std;
//using ll = long long;
#define out(s) cout << (s) << endl;

int dp[1010][1010];

int main()
{
	int W, N;
	cin >> W;
	vector<tuple<int, int>> anss;
	int cnt = 1;
	while (W!=0)
	{
		cin >> N;
		memset(dp, -1, sizeof(dp));
		dp[0][0] = 0;
		for (size_t i = 0; i < N; i++)
		{
			int vi, wi;
			scanf("%d,%d", &vi, &wi);
			for (size_t n = 0; n <= W; n++)
			{
				if (dp[i][n] != -1) {
					dp[i + 1][n] = max(dp[i][n], dp[i + 1][n]);
					if (n + wi > W)continue;
					dp[i + 1][n + wi] = max(dp[i][n] + vi, dp[i][n]);
				}
			}
		}
		int dp_max = *max_element(dp[N], dp[N] + W + 1);
		int index = 0;
		for (size_t i = 0; i < W+1; i++)
		{
			if (dp_max == dp[N][i]) { index = i; break; }
		}
		cout << "Case " << cnt << ":" << endl;
		cout << dp_max << endl;
		cout << index << endl;
		cin >> W;
		cnt++;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:31: error: 'max_element' was not declared in this scope
   38 |                 int dp_max = *max_element(dp[N], dp[N] + W + 1);
      |                               ^~~~~~~~~~~
Language: C++

const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???

// ??\???
int n, W;
int w[MAX_N], v[MAX_N];

// ?????¢??????????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
// -1????????????????±??????§???????????¨?????¨???
int dp[MAX_N + 1][MAX_W + 1];

// i????????\?????????????????????????????????j??\?????????????????????????????¨?????????
// ???????????????????????????????????§??????????????¢??°
int rec_dp(int i, int j) {
  if (dp[i][j] != -1) {
    // ?????§?????????????????¨??????????????????????????????????????¨
    return dp[i][j];
  }
  int res;
  if (i == n) {
    // ????????????????????£??????????????¨?????????????????????????????§??????0??§?¢????
    res = 0;
  } else if (j < w[i]) {
    // ???????????????????¶?????????????i?????\????????????????????§?????\?????????????????????????????????
    res = rec_dp(i + 1, j);
  } else {
    // ??????i?????\???????????\??????????????????????????§???????????????????????????????????§?????????????????¶
    res = max(
        rec_dp(i + 1, j),
        rec_dp(i + 1, j - w[i]) + v[i]
    );
  }
  // ?????????????????????????¨???¶??????
  return dp[i][j] = res;
}

void solve_dp() {
  memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
//  for (int i = 0; i < MAX_N + 1; i++)
//    for (int j = 0; j < MAX_W + 1; j++)
//      dp[i][j] = -1;
  
  // 0????????\?????§??????W??\????????´?????????????????¨?????????
  cout << rec_dp(0, W) << endl;
}

Compiler output:
a.cc: In function 'int rec_dp(int, int)':
a.cc:29:11: error: 'max' was not declared in this scope
   29 |     res = max(
      |           ^~~
a.cc: In function 'void solve_dp()':
a.cc:39:3: error: 'memset' was not declared in this scope
   39 |   memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
      |   ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | const int MAX_N = 1000; // n????????§???
a.cc:45:3: error: 'cout' was not declared in this scope
   45 |   cout << rec_dp(0, W) << endl;
      |   ^~~~
a.cc:45:27: error: 'endl' was not declared in this scope
   45 |   cout << rec_dp(0, W) << endl;
      |                           ^~~~
Language: C++

const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???

// ??\???
int n, W;
int w[MAX_N], v[MAX_N];

// DP????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
int dp[MAX_N + 1][MAX_W + 1];

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

Compiler output:
a.cc: In function 'void solve_dp2()':
a.cc:21:20: error: 'max' was not declared in this scope
   21 |         dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
      |                    ^~~
a.cc:24:3: error: 'cout' was not declared in this scope
   24 |   cout << dp[0][W] << endl;
      |   ^~~~
a.cc:24:23: error: 'endl' was not declared in this scope
   24 |   cout << dp[0][W] << endl;
      |                       ^~~~
Language: C++

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define INF 1<<25
 
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}

int W,N;
int v[1001],w[1001];
int dp[1001][1001];

int main(){
	int cnt=1;
	while(cin>>W){
		if(W==0)break;
		cin>>N;
		rep(i,N)cin>>v[i]>>w[i];
		REP(i,1,N+1){
			rep(j,W+1){
				if(w[i-1]<=j)
					dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
				else 
					dp[i][j]=dp[i-1][j];
			}
		}
		int ans_v=0,ans_w=0;
		rep(i,W+1){
			if(dp[N][i]>ans_v){
				ans_v=dp[N][i];
				ans_w=i;
			}
		}
		cout<<"Case "<<cnt<<<<":"<<endl;
		cout<<ans_v<<endl;
		cout<<ans_w<<endl;
		cnt++;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:68:37: error: expected primary-expression before '<<' token
   68 |                 cout<<"Case "<<cnt<<<<":"<<endl;
      |                                     ^~
Language: C++

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int dp[1001][1001];
int N, W;
int v[1001], w[1001];

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

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

int main() {
	int now = 1;
	while (1) {
		cin >> W;
		if (W == 0)break;
		cin >> N;
		for (int i = 0; i < N; i++) {
			scanf_s("%d,%d", v + i, w + i);
		}

		for (int i = 0; i <= N; i++) {
			for (int j = 0; j <= W; j++) {
				dp[i][j] = -1;
			}
		}
		solve(0, W);
		for (int i = 0; i <= N; i++) {
			for (int j = 0; j <= W; j++) {
				cout << i << ":" << j<<"=" << dp[i][j] << endl;
			}
		}
		int value = -1; int weight;
		for (int i = 0; i <= W;i++) {
			if (value < dp[0][i]) {
				value = dp[0][i];
				weight = i;
			}
		}
		cout << "Case " << now++ << ":" << endl << value << endl << weight-1 << endl;
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:25: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   32 |                         scanf_s("%d,%d", v + i, w + i);
      |                         ^~~~~~~
      |                         scanf
Language: C++

#include<iostream>
using namespace std;
int main(){
  int W,N;
  int count = 0;
  while(cin >> W){
    if(W==0) break;
    cin >> N;
    count++;
    int item[W+1];
    for(int i=0;i<=W;i++) item[i]


Compiler output:
a.cc: In function 'int main()':
a.cc:11:34: error: expected ';' at end of input
   11 |     for(int i=0;i<=W;i++) item[i]
      |                                  ^
      |                                  ;
a.cc:11:34: error: expected '}' at end of input
a.cc:6:18: note: to match this '{'
    6 |   while(cin >> W){
      |                  ^
a.cc:11:34: error: expected '}' at end of input
   11 |     for(int i=0;i<=W;i++) item[i]
      |                                  ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

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

struct treasure{
	int value;
	int weight;
};

bool comp(treasure t1, treasure t2){
	if(t1.weight <= t2.weight) return true;
	else return false;
}

int main(){
	int w;
	const int maxw = 10000;
	int count = 1;
	while(cin >> w){
		if(w == 0) break;
		int n;
		int cost[maxw + 1];
		int best[maxw + 1];
		for(int i = 0; i <= maxw; i++){
			cost[i] = 0;
			best[i] = 0;
		}
		vector<treasure> treasures;
		cin >> n;
		for(int i = 0; i < n; i++){
			treasure t;
			char c;
			cin >> t.value >> c >> t.weight;
			treasures.push_back(t);
		}
		sort(treasures.begin(), treasures.end(), comp);
		for(int j = 0; j < n; j++){
			for(int k = 1; k <= w; k++)
				if(k >= treasures[j].weight)
					if(cost[k] < cost[k - treasures[j].weight] + treasures[j].value)
					{
						cost[k] = cost[k - treasures[j].weight] + treasures[j].value;
						best[k] = j;
					}
		}
		cout << "Case" << " " << count++ << ":" << endl;
	cout << total << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:17: error: 'total' was not declared in this scope
   48 |         cout << total << endl;
      |                 ^~~~~
Language: C++

//0042 A Thief
//vñFibvTbNâè

#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;

int main(void)
{

	const int MAX_WEIGHT = 1000;
	const int MAX_OBJECT = 10000;
	const int MAX_SCORE = 1000;

	struct Obj
	{
		int w;
		int score;
	};
	struct Cloth
	{
		int index;
		int totalScore;
	};

	int caseNum = 1;
	while(1)
	{
		//ÇÌd³ÌÆ«àAÅãÉüê½CfbNXA»êÜÅÌ¿lð¶ÝµÈ¢lÉ
		int totalScore[MAX_WEIGHT+1] = {0};
		int intoIndex[MAX_WEIGHT+1];
		memset(intoIndex, 0xffffffff, sizeof(intoIndex)/sizeof(intoIndex[0]));

		//\¢Ì¶áfobOÅl©êÈ¢æI
		//Cloth total[MAX_WEIGHT+1];

		Obj obj[MAX_OBJECT];

		int w, n;
		int i, j;
		char dummy;

		cin >> w;
		if(w == 0)
			break;
		cin >> n;

		for(i = 0; i < n; i++)
		{
			cin >> obj[i].score >> dummy >> obj[i].w;
			
			for(j = w-obj[i].w; j >= 1; j--)
			{
				//·ÅÉ»Ìd³ÜÅÏÜê½àÌª é
				if(totalScore[j])
				{
					//æèæ¢ÂÝûð­©
					if(totalScore[j+ obj[i].w] < totalScore[j] + obj[i].score)
					{
						totalScore[j+ obj[i].w] = totalScore[j] + obj[i].score;
						intoIndex[j+ obj[i].w] = i;
					}
				}
			}
			//ÅÌÍüêÄà¢¢Ìæ
			if(totalScore[obj[i].w] < obj[i].score)
			{
				totalScore[obj[i].w] = obj[i].score;
				intoIndex[obj[i].w] = i;
			}
		}

		cout << "Case " << caseNum << ":" << endl;
		caseNum++;

		//zñÉüÁ½vfÌÅålÆA»ÌCfbNXðT·
		int maxScore = 0;
		int maxIndex = -1;
		for(i = 0; i <= w; i++)
		{
			if(totalScore[i] && maxScore<totalScore[i])
			{
				maxScore = totalScore[i];
				maxIndex = i;
			}
		}
		//½©vfÍüÁÄ½H
		if(maxIndex >= 0)
		{
			cout << totalScore[maxIndex] << endl;

			//d³aÌvZ
			int totalW = 0;
			int index = maxIndex;
			while(index>0)
			{
				totalW += obj[ intoIndex[index] ].w;
				index -= obj[ intoIndex[index] ].w;
			}
			cout << totalW << endl;
		}
		//êÂàüçÈ©Á½H
		else
			cout << "0" << endl << "0" << 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(intoIndex, 0xffffffff, sizeof(intoIndex)/sizeof(intoIndex[0]));
      |                 ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    6 | #include<algorithm>
  +++ |+#include <cstring>
    7 | using namespace std;
Language: C++

#include<cstdio>
#include<algorithm>
#include<windows.h>

using namespace std;

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

int main(void){
	while(scanf("%d", &W)&&W){
		int ans;
		scanf("%d", &N);
		for(int i = 1; i <= N; i++){
			scanf("%d,%d", &p[i], &w[i]);
		}
		for(int i = 1; i <= N; i++){
			for(int j = 1;j <= W; j++){
				if(i-1 < 0 || j-w[i]<0)continue;
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+p[i]);
			}
		}
		c++;
		printf("Case%2d:\n",c);
		printf("%d\n",dp[N][W]);
		for(int i = 0; i < W; i++){
			if(dp[N][W] == dp[N][W-i]){
				ans = i;
			}
		}
		printf("%d\n",W-ans);
		/*ツ渉可甘コツ可サ*/
		for(int i = 0; i < 1001; i++){
			w[i] = 0;
			p[i] = 0;
		}
		for(int i = 0; i < 10001; i++){
			for(int j = 0; j < 1000; j++){
				dp[i][j] = 0;
			}
		}
	}
	return 0;
}

Compiler output:
a.cc:3:9: fatal error: windows.h: No such file or directory
    3 | #include<windows.h>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C++

c[2001],w[2001];
dp[1002][2001];
#define max(a,b) a>b?a:b
N,W,r,x;main(o,i,j){
	for(;scanf("%d%d",&W,&N),W;printf("Case %d:\n%d\n%d\n",o++,r,x),memset(dp,0,sizeof dp)){
		for(r=N;r--;)scanf("%d,%d",c+r,w+r);
		for(i=0;i<=N;i++)for(j=0;j<=W;j++){
			//if(i)dp[i][j]=max(dp[i][j],dp[i-1][j]);
			dp[i+1][j+w[i]]=max(dp[i+1][j+w[i]],dp[i][j]+c[i]);
			if(r<dp[i][j])r=dp[i][j],x=j;
		}
	}
}

Compiler output:
a.cc:1:1: error: 'c' does not name a type
    1 | c[2001],w[2001];
      | ^
a.cc:2:1: error: 'dp' does not name a type
    2 | dp[1002][2001];
      | ^~
a.cc:4:1: error: 'N' does not name a type
    4 | N,W,r,x;main(o,i,j){
      | ^
a.cc:4:13: error: expected constructor, destructor, or type conversion before '(' token
    4 | N,W,r,x;main(o,i,j){
      |             ^
Language: C++

t[9999][9999],j;main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,220,49)){
		for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--);
	}
}

Compiler output:
a.cc:1:1: error: 't' does not name a type
    1 | t[9999][9999],j;main(p,W,a,b,c){
      | ^
a.cc:1:21: error: expected constructor, destructor, or type conversion before '(' token
    1 | t[9999][9999],j;main(p,W,a,b,c){
      |                     ^
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define MAX 1010

int W,N;
int w[MAX],v[MAX];
ll dp[MAX][MAX];

int main(){
  int i,j;

  for(;;){
    scanf("%d",&W); if(W == 0) break;
    scanf("%d",&N);
    rep(i,N) scanf("%d,%d",&v[i],&w[i]);

    rep(i,MAX) rep(j,MAX) dp[i][j] = 0;

    int res;
    for(i = 0; i <= N; i++){
      for(j = 0; j <= W; j++){
        if(j - w[i] < 0) dp[i+1][j] = dp[i][j];
        else {
          if(dp[i][j] < dp[i][j-w[i]] + v[i]){
            dp[i+1][j] = dp[i][j-w[i]] + v[i];
            res = j;
          }
          else dp[i+1][j] = dp[i][j];
        }
      }
    }

    printf("%d\n%d\n",dp[N][W],res);
  }

  return 0;
}

Compiler output:
a.cc:23:1: error: 'll' does not name a type
   23 | ll dp[MAX][MAX];
      | ^~
a.cc: In function 'int main()':
a.cc:33:27: error: 'dp' was not declared in this scope
   33 |     rep(i,MAX) rep(j,MAX) dp[i][j] = 0;
      |                           ^~
a.cc:38:26: error: 'dp' was not declared in this scope
   38 |         if(j - w[i] < 0) dp[i+1][j] = dp[i][j];
      |                          ^~
a.cc:40:14: error: 'dp' was not declared in this scope
   40 |           if(dp[i][j] < dp[i][j-w[i]] + v[i]){
      |              ^~
a.cc:49:23: error: 'dp' was not declared in this scope
   49 |     printf("%d\n%d\n",dp[N][W],res);
      |                       ^~
Language: C++

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

int main(){
	int caseNum = 1;
	int ans;
	int W, n;
	int v[MAX_N];
	int w[MAX_N];
	int dp[MAX_N][MAX_W];
	while(cin >> W){
		if(W == 0){
			break;
		}
		cin >> n;
		for (int i = 0; i < n; i++) {
			scanf("%d,%d", &v[i], &w[i]);
		}
		
		memset(dp, 0, sizeof(dp));
		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]);
				}
			}
		}
		// answer
		cout << "Case " << caseNum++ << ":" << endl;
		for (int i = W; i >= 0; i--) {
			if(dp[n][W] != dp[n][i]) {
				ans = i+1;
				break;
			}
		}
		cout << dp[n][W] << endl;
		cout << ans << endl;
	}
	return 0;
}

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

#include<iostream>

using namespace std;

const int MAX_w = 1000;
const int MAX_v = 10000;

int dp[MAX_w + 1][MAX_v + 1];


int n, wet ;
int w[MAX_w], v[MAX_v];

// i番目以降の品物から重さの和がj以下なるように選んだときの、
// 取りうる価値の総和の最大値を返す関数
int rec(int i, int j) {
  int res;
  if(dp[i][j] != -1){
  	
	return dp[i][j];
  }

  if (i == n) {
    // 品物がもう残っていないときは、価値の和の最大値は0で確定
    res = 0;
  } else if (j < w[i]) {
    // 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
    // i+1 以降の品物のみを使ったときの最大値をそのままこの場合の最大値にする
    res = rec(i + 1, j);
  } else {
    // 品物iを入れるか入れないか選べるので、両方試して価値の和が大きい方を選ぶ
    res = max(
        rec(i + 1, j),
        rec(i + 1, j - w[i]) + v[i]
    );
  }

  return res;
}

void solve(int ca) {
  // 0番目以降で容量W以下の場合の結果を表示する
  int wmin;
  
  memset(dp, -1, sizeof(dp));
  
  cout << "Case" << " " << ca << ":" <<endl; 
  
  int ans =  rec(0, wet) ;
  cout << ans << endl;
  
  for (int w = wet -1 ; w>=0 ; w--){
  	if( ans != rec(0,w)){
		 wmin = w+1;
		 break;
  	}
  }
  
  cout << wmin << endl;  
  
}


int main(){
	
	char x;
	int ca = 0;
	
	while(1){
			
		ca++;
		cin >> wet;
		if(wet == 0 ) break;
		cin >> n;
		
		for(int i = 0 ;  i<n ; i++){
			
			cin >> v[i] >> x >> w[i];
		}
		
		
		 solve(ca);
		
	}
	
	return 0;
	
} 

Compiler output:
a.cc: In function 'void solve(int)':
a.cc:45:3: error: 'memset' was not declared in this scope
   45 |   memset(dp, -1, 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 |
Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

int W, N, casenum = 0, ans, wmin;
int v[1000], w[1000];
int dp[1001][1001];

int rec_dp(int, int);
void solve();

int main(){
	int i;
	char c;
		
	while(1){
		cin >> W >> N;
		if(W == 0)
			break;
		
		casenum++;
		for(i = 0; i < N; i++)
			cin >> v[i] >> c >> w[i];
		
		memset(dp, -1, sizeof(dp));
		ans = rec_dp(0, W);
		
		for(i = 0; i < W; i++){
			if(rec_dp(0, i) == ans){
				wmin = i;
				break;
			}
		}
		
		solve();
	}
	
	return 0;
}

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

void solve(){
	cout << "Case" << " " << casenum << ":" << endl;
	cout << ans << endl;
	cout << wmin << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:17: error: 'memset' was not declared in this scope
   26 |                 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++

#include<iostream>
#include<stdio.h>

int dp[1000][10000];
int W;
int n;
int v[1000], w[1000];
int now = 1;

int main()
{
	while( 1 ){
		memset( dp, 0, sizeof( dp ) );
		scanf( "%d", &W );
		if( !W ) break;
		scanf( "%d", &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 = 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], dp[i][j-w[i]] + v[i] );
				}
			}
		}
		
		int res = W;
		for( int i = W; i >= 0; i-- ){
			if( dp[n][i] == dp[n][W] ) res = std::min( res, i );
			else break;
		}
		
		printf( "Case %d:\n", now );
		printf( "%d\n%d\n", dp[n][W], res );
		
		now++;	
	}
	

 	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:17: 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 | #include<stdio.h>
Language: C++

// 他人のを拝借
#include <iostream>#include <algorithm>#include <cassert>#include <cctype>#include <cstdio>#include <math.h>#include <map>#include <queue>#include <string>using namespace std; int W,N,v[1000],w[1000],dp[1001][1001];char c; int main(){    int cn=0;    while(cin>>W){        if(W==0)return 0;        cn++;        cin>>N;        for(int i=0;i<N;i++)cin>>v[i]>>c>>w[i];        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]);            }        }        int V=dp[N][W],w2=W;        while(dp[N][w2]==V)w2--;        cout<<"Case "<<cn<<":"<<endl<<dp[N][W]<<endl<<w2+1<<endl;    }} 

Compiler output:
a.cc:2:20: warning: extra tokens at end of #include directive
    2 | #include <iostream>#include <algorithm>#include <cassert>#include <cctype>#include <cstdio>#include <math.h>#include <map>#include <queue>#include <string>using namespace std; int W,N,v[1000],w[1000],dp[1001][1001];char c; int main(){    int cn=0;    while(cin>>W){        if(W==0)return 0;        cn++;        cin>>N;        for(int i=0;i<N;i++)cin>>v[i]>>c>>w[i];        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]);            }        }        int V=dp[N][W],w2=W;        while(dp[N][w2]==V)w2--;        cout<<"Case "<<cn<<":"<<endl<<dp[N][W]<<endl<<w2+1<<endl;    }}
      |                    ^
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
    int size;
    int case_count = 1;
    
    
    while(cin>>size){
        //size==0なら終了
        if(size==0){
            break;
        }
        
        //データの入力
        int num;
        cin>>num;
        int val[num];
        int wei[num];
        for(int i=0; i<num; i++)scanf("%d,%d",&val[i],&wei[i]);
        
        //計算
        int dp[size+1];
        int dp_temp[size+1];
        int dp_val[size+1];
        for(int i=0; i<=size; i++){
            dp[i]=0;
            dp_val[i]=0;
        }
        dp[0]=1;

        for(int i=0; i<num; i++){
            memcpy(dp_temp,dp,sizeof(dp));
            for(int j=0; j<=size; j++){
                if(dp[j]==1){
                    int next_wei=j+wei[i];
                    int next_val=dp_val[j]+val[i];
                    if(next_wei<=size){
                        if(dp_val[next_wei]<next_val){
                            dp_temp[next_wei]=1;
                            dp_val[next_wei]=next_val;
                        }
                    }
                }
            }
            memcpy(dp,dp_temp,sizeof(dp_temp));
        }
        int max_val=0;
        int min_wei=0;
        for(int i=0; i<=size; i++){
            if(max_val<dp_val[i]){
                max_val=dp_val[i];
                min_wei=i;
            }
        }
        cout<<"Case "<<case_count<<":"<<endl;
        cout<<max_val<<endl;
        cout<<min_wei<<endl;
        case_count++;
        
    }
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:13: error: 'memcpy' was not declared in this scope
   44 |             memcpy(dp_temp,dp,sizeof(dp));
      |             ^~~~~~
a.cc:12:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   11 | #include <bitset>
  +++ |+#include <cstring>
   12 |
Language: C++

import java.lang.*;
import java.util.*;

public class Main
{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[])
    {
	for(int k=1; ;k++){
	    int W = sc.nextInt();
	    if(W==0)break;
	    
	    int n = sc.nextInt();
	    
	    int[] dp = new int[W+1];
	    for(int i=0; i<W; i++){
		dp[i]=0;
	    }
	    
	    int dv,dw;
	    for(int i=0; i<n; i++){
		String[] s = sc.next().split(",");
		dv = Integer.parseInt(s[0]); //value
		dw = Integer.parseInt(s[1]); //weight
		for(int j=W; j>=0; j--){
		    if(j == dw) dp[j]=Math.max(dp[j], dv);
		    else if(dp[j] != 0 && j+dw <= W) dp[j+dw]=Math.max(dp[j+dw], dv+dp[j]);
		}
	    }
	      
	    int[] max = new int[2];
	    max[0] = -1; //[0]dv [1]i
	    for(int i=W; i>0; i--){
		if(max[0] <= dp[i]){
		    max[0] = dp[i];
		    max[1] = i;
		}
	    }
	    System.out.println("Case " + k + ":\n" + max[0] +"\n" + max[1]);
	}
    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.lang.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: expected unqualified-id before 'public'
    4 | public class Main
      | ^~~~~~
Language: C++


// dpの練習
// dpでなく、愚直に組んだプログラミング
// ナップサック問題とほぼ同じ

#include <iostream>
#include <algorithm>

using namespace std;

int wei; // 持てる最大の重さ
int n; // お宝の数
int v[1001]; // お宝の価値
int w[1001]; // お宝の重さ
 // グローバル配列は0で初期化されている
int dp[1001][1001]; //メモテーブル

int max_value(int i, int j) {
  int value;

  if( dp[i][j] >= 0 ){
    return dp[i][j];
    //すでに１回は調べている
  }
 
  if (i == n) {
    // 品物がもう残っていないときは、価値の和の最大値は0で確定
    //もうお宝がないつまり、価値は0
    value = 0;
  } else if (j < w[i]) {
    //風呂敷が持てる重さを超えてしまう
    // 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
    // i+1 以降の品物のみを使ったときの最大値をそのままこの場合の最大値にする
    value = max_value(i + 1, j);
  } else {
    //左がお宝を入れない、右がお宝を入れた場合
    // 品物iを入れるか入れないか選べるので、両方試して価値の和が大きい方を選ぶ
    value = max( max_value(i + 1, j), max_value(i + 1, j - w[i]) + v[i] );
  } 
  return dp[i][j] = value;
  //メモに記憶させる
}

void max_weight( int ans ){

  int w_min;
   
  for (int i = wei -1 ; i >= 0 ; i--){
    if( ans != max_value( 0 , i ) ){
         w_min = i + 1;
         break;
    }
  }
  cout << w_min << endl;  
}


int main(void){

  int cnt = 1;
  while( cin >> wei ){
    memset( dp , -1 , sizeof(dp) );
    //まだ調べてないところを-1で初期化
    if( wei == 0 )break;
    cin >> n;
    char ten;
    for( int i = 0 ; i < n ; i++ ){
      cin >> v[i] >> ten >> w[i];
    }
    cout << "Case " << cnt << ":" << endl;
    int ans = max_value( 0 , wei );
    cout << ans << endl;
    max_weight(ans);
    cnt++;
  }
  return 0;
}

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

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, int> obj;

int main(){
  int N, W, weight, value;
  char ch;
  int case_num = 1;

  while(1){
    cin >> W;
    if(W == 0) break;
    cin >> N;

    //printf("W = %d N = %d\n", W, N);

    vector<obj> obj_list;
    int dp[2][1010];
    memset(dp, -1, sizeof(dp));
    
    for(int i = 0; i < N; i++){
      cin >> value >> ch >> weight;
      obj_list.push_back(obj(value, weight));
      //printf("value = %d weight = %d\n", value, weight);
    }

    dp[0][0] = 0;
    dp[1][0] = 0;

    for(int i = 0; i < N; i++){
      obj o = obj_list[i];

      for(int j = 0; j <= W; j++){
        if(dp[(i+1)%2][j] != -1 && j + o.second <= W){
          dp[i%2][j+o.second] = max(dp[i%2][j+o.second], dp[(i+1)%2][j] + o.first);
        }
      }
    }
    int answer = 0;
    int answer_weight = 0;

    for(int i = 0; i <= W; i++){
      if(answer < dp[(N+1)%2][i]){
        answer = dp[(N+1)%2][i];
        answer_weight = i;
      }
    }

    cout << "Case " << case_num << ":" << endl;
    cout << answer << endl;
    cout << answer_weight << endl;

    case_num++;
  }

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:5: error: 'memset' was not declared in this scope
   23 |     memset(dp, -1, sizeof(dp));
      |     ^~~~~~
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<algorithm>
#include<cstdio>
#include<vector>

using namespace std;

int N,W;

struct Treasurea
{

	int value;
	int weight;
	int flag;

	Treasurea()
	{

		value = 0;
		weight = 0;
		flag = false;

	}

};

struct Memo
{

	Treasurea record;
	bool flag;

	Memo()
	{

		flag = false;

	}

};

Memo memo[1001][1001];

Treasurea knapsack(vector<Treasurea> &treasurea, int correntWeight, int correntValue, int step)
{
	/*
	if(correntWeight < 0)
	{

		Treasurea temp;
		temp.value = correntValue - treasurea[step- 1].value;
		temp.weight = W - (correntWeight + treasurea[step- 1].weight);
		return temp;

	}
	*/
	if(treasurea.size() == step)
	{

		Treasurea temp;
		temp.value = correntValue;
		temp.weight = W - correntWeight;
		return temp;

	}
	else if(memo[correntWeight][step].flag) return memo[correntWeight][step].record;


	Treasurea total;

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

		if(treasurea[i].flag) continue;
			treasurea[i].flag = true;
		
		Treasurea temp;

		if(correntWeight - treasurea[i].weight >= 0)  temp = knapsack(treasurea,correntWeight - treasurea[i].weight, correntValue + treasurea[i].value, step + 1);
		else
		{
			temp.value = correntValue;
			temp.weight = W - correntWeight;
		}

		if( (total.value < temp.value) || (total.value == temp.value && total.weight > temp.weight))	total = temp;

		treasurea[i].flag = false;

	}

	memo[correntWeight][step].record = total; 
	memo[correntWeight][step].flag = true;

	return total;

}

int main()
{

	int case_count = 0;
	
	while(cin >> W && W != 0)
	{
		
		cin >> N;

		vector<Treasurea> treasurea(N);
		Treasurea result;

		for(int i = 0; i < N; ++i)	scanf("%d,%d",&treasurea[i].value,&treasurea[i].weight);			

		result = knapsack(treasurea,W,0,0);

		memset(memo,0,sizeof(memo));

		cout << "Case " << ++case_count << ":" << endl << result.value << endl << result.weight << endl;

		treasurea.clear();

	}

}

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

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

int dp[1001][1001];

int main()
{
	int c = 1;

	while(1)
	{

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

		int w, n;
		cin>>w>>n;
		if(w == 0)break;
		int treasure[1000];
		int price[1000];

		for(int i = 0; i < n; i++)
			scanf("%d,%d", &price[i], &treasure[i]);

		for(int i = 0; i < n; i++){
			for(int j = 0; j <= w; j++){
				if(j < treasure[i])
					dp[i + 1][j] = dp[i][j];
				else
					dp[i + 1][j] = max(dp[i][j], dp[i][j - treasure[i]] + price[i]);
			}
		}
	
		int ansWeight;
		for(ansWeight = w - 1; w >= 0; ansWeight--)
			if(dp[n][w] > dp[n][ansWeight])break;
			
		cout << "Case" << c++ <<":"<<endl;
		cout << dp[n][w] << endl;
		cout << ansWeight + 1 << endl;
	}

	return 0;
}

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

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

using namespace std;
int N;
vector<int> w;
vector<int> v;
int dp[1001][1001];

void solve()
{
	int W;
	int count = 1;
	while(cin >> W, W)
	{
		memset(dp, 0, sizeof(dp));
		cin >> N;
		w.resize(N);
		v.resize(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 = 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]);
				}
			}
		}
		int pos = 0;
		for(int i = 0; i <= W; ++i)
		{
			if(dp[N][i] > dp[N][pos])
			{
				pos = i;
			}
		}
		cout << "Case " << count << ":" << endl;
		cout << dp[N][pos] << " " << pos << endl;
		++count;
	}
}

int main()
{
	solve();
	return(0);
}

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

#include "math.h"
#include "stdio.h"
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>

using namespace std;


/** Problem0042 : A Thief
 Time Limit Exceeded **/

#define MAX_N 1100
#define MAX_W 1100

int W, N, tre[1100][2]={0}, solW, solN;
int dp[MAX_N][MAX_W];

pair<int, int> solve(int i, int j)
{
	if (dp[i][j] >= 0)
		return pair<int, int>(dp[i][j], j);
	
	pair<int, int> res;
	if (i == N) {
		res = pair<int, int>(0, W-j);
	} else if (j < tre[i][1]) {
		res = solve(i+1, j);
	} else {
		//res.first = max(solve(i+1, j).first, solve(i+1, j-tre[i][1]).first+tre[i][0]);
		
		if (solve(i+1, j).first > solve(i+1, j-tre[i][1]).first+tre[i][0]) {
			res = solve(i+1, j);
		} else if (solve(i+1, j).first < solve(i+1, j-tre[i][1]).first+tre[i][0]) {
			res = pair<int, int>(solve(i+1, j-tre[i][1]).first+tre[i][0], solve(i+1, j-tre[i][1]).second);
		} else {
			res = pair<int, int>(solve(i+1, j).first, min(solve(i+1, j).second, solve(i+1, j-tre[i][1]).second));
		}
	}
	return res;
}

int main()
{
	int set=0; char cam;
	while (1) {
		set++;
		
		cin >> W;
		solW = 0; solN = 0;
		if (W==0) break;
		cin >> N;
		
		memset(dp, -1, sizeof(dp));
		
		for (int i=0; i<N; i++) {
			cin >> tre[i][0] >> cam >> tre[i][1];
		}
		
		pair<int, int> sol = solve(0, W);
		
		cout << "Case " << set << ":" << endl;
		cout << sol.first << endl;
		cout << sol.second << endl;
	}
	return 0;
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:55:17: error: 'memset' was not declared in this scope
   55 |                 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 <iostream>
  +++ |+#include <cstring>
    7 |
Language: C++


import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		for (int c=1;;c++) {
			int W = sc.nextInt();
			if (W == 0) break;
			
			int n = sc.nextInt();
			int[] v = new int[n], w = new int[n];
			for (int i=0;i<n;i++) {
				String[] ws = sc.next().split(",");
				v[i] = Integer.valueOf(ws[0]); w[i] = Integer.valueOf(ws[1]);
			}
			
			int[] dp = new int[W+1];
			fill(dp, -1); dp[0] = 0;
			for (int i=0;i<n;i++) for (int j=W;j>=w[i];j--) if (dp[j-w[i]]>=0){
				dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
			}
			int aw = 0, av = 0;
			for (int i=0;i<=W;i++) if (av < dp[i]){
				av = dp[i];
				aw = i;
			}
			System.out.println("case " + c + ":");
			System.out.println(av);
			System.out.println(aw);
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Compiler output:
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.io.*;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import static java.util.Arrays.*;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import static java.util.Collections.*;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import static java.lang.Math.*;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: expected unqualified-id before 'public'
    8 | public class Main {
      | ^~~~~~
Language: C++

#include <iostream>
using namespace std;

int W;
int w[1001],v[1001];
int N;
int dp[1001][1001];

int rec(int i, int j){

  //テ」ツつづ」ツ??」ツつ?」ツ?」テ」ツ??
  if(dp[i][j] >= 0){
    return dp[i][j];
  }
  int 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]);
    /* 
   int tmp1,tmp2;
    tmp1 = rec(i+1,j);
    tmp2 = rec(i+1,j-w[i]) + v[i];
    if(tmp1 < tmp2){
      res = tmp2;
    }else{
      res = tmp1;
    }
    */
  }
  return dp[i][j] = res;
}


int main(){

  int num = 1;

  while(1){
    cin >> W;
    if(W == 0) break;
    cin >> N;
    //テ・ツ按敕ヲツ慊淌・ツ個?
    /*
    for(int i = 0; i < 1001; i++){
      w[i] = v[i] = -1;
      for(int j = 0; j < 1001; j++)
	dp[i][j] = -1; 
    }
    */
    memset(dp,-1,sizeof(dp));
    memset(w,-1,sizeof(w));
    memset(v,-1,sizeof(v));


    //テ・ツ?・テ・ツ環?
    char tmp;
    for(int i = 0; i < N; i++) cin >> v[i] >> tmp >> w[i];

    int ans = rec(0,W);

    // dpテゥツ?催・ツ按療」ツつ津・ツ?ィテ」ツ?ヲテ・ツ淞凝」ツつ?」ツつ?
    for(int i = 0; i < N; i++){
      for(int j = 0; j <= W; j++){
	if(dp[i][j] == -1)
	  rec(i,j);
      }
    }   
  
    cout << "Case "<< num  << ":"<< endl;
    num++;
    cout << ans << endl; 
    int j;
    for( j = 0; dp[0][j] != ans ; j++){}
    cout << j << endl;
    
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:5: error: 'memset' was not declared in this scope
   56 |     memset(dp,-1,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 | using namespace std;