Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	auto start = high_resolution_clock::now(); 

	int n, w;
	cin >> n >> w;
	vector<int> wt(n), v(n);
	for(int i = 0 ; i < n ; i++)
		cin >> wt[i] >> v[i];

	unordered_map<int, int> mymap;
	unordered_map<int, int>::iterator it;
	mymap[0] = 0;
	for (int i = 0 ; i < n ; i++){
		unordered_map<int, int> mymap2(mymap);
		for(it = mymap.begin(); it != mymap.end(); it++){
			if(it->first + wt[i] <= w){
				if(mymap.find(it->first + wt[i]) != mymap.end())
					mymap2[it->first + wt[i]] = max(it->second + v[i] , mymap[it->first + wt[i]]);
				else
					mymap2[it->first + wt[i]] = it->second + v[i];
			}
		}
		mymap = mymap2;
	}

	int maxv = -1;
	for(it = mymap.begin(); it != mymap.end(); it++){
		// trace2(it->first, it->second)
		maxv = max(maxv, it->second);
	}

	cout << maxv;
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:9: error: 'unordered_map' was not declared in this scope
   47 |         unordered_map<int, int> mymap;
      |         ^~~~~~~~~~~~~
a.cc:16:1: note: 'std::unordered_map' is defined in header '<unordered_map>'; this is probably fixable by adding '#include <unordered_map>'
   15 | #include <chrono>
  +++ |+#include <unordered_map>
   16 | 
a.cc:47:23: error: expected primary-expression before 'int'
   47 |         unordered_map<int, int> mymap;
      |                       ^~~
a.cc:48:23: error: expected primary-expression before 'int'
   48 |         unordered_map<int, int>::iterator it;
      |                       ^~~
a.cc:49:9: error: 'mymap' was not declared in this scope
   49 |         mymap[0] = 0;
      |         ^~~~~
a.cc:51:31: error: expected primary-expression before 'int'
   51 |                 unordered_map<int, int> mymap2(mymap);
      |                               ^~~
a.cc:52:21: error: 'it' was not declared in this scope; did you mean 'i'?
   52 |                 for(it = mymap.begin(); it != mymap.end(); it++){
      |                     ^~
      |                     i
a.cc:55:41: error: 'mymap2' was not declared in this scope
   55 |                                         mymap2[it->first + wt[i]] = max(it->second + v[i] , mymap[it->first + wt[i]]);
      |                                         ^~~~~~
a.cc:57:41: error: 'mymap2' was not declared in this scope
   57 |                                         mymap2[it->first + wt[i]] = it->second + v[i];
      |                                         ^~~~~~
a.cc:60:25: error: 'mymap2' was not declared in this scope
   60 |                 mymap = mymap2;
      |                         ^~~~~~
a.cc:64:13: error: 'it' was not declared in this scope; did you mean 'wt'?
   64 |         for(it = mymap.begin(); it != mymap.end(); it++){
      |             ^~
      |             wt