Language: C++

#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

map<int,long long> D[2];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, W;
	long long ans=0;
	cin>>N>>W;
	memset(D,-1,sizeof(D));
	D[0]=0;
	for(int i=1;i<=N;i++) {
		int w, v;
		cin>>w>>v;
		for(auto V: D[(i-1)&1]) {
			D[i&1][V.first]=max(D[i&1][V.first],V.second);
			if(V.first+w<=W) {
				D[i&1][V.first+w]=max(D[i&1][V.first+w],V.second+v);
				ans=max(ans,D[V.first+w]);
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:14: error: no match for 'operator=' (operand types are 'std::map<int, long long int>' and 'int')
   24 |         D[0]=0;
      |              ^
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:331:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = int; _Tp = long long int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, long long int> >]'
  331 |       operator=(const map&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:331:17: note:   no known conversion for argument 1 from 'int' to 'const std::map<int, long long int>&'
  331 |       operator=(const map&) = default;
      |                 ^~~~~~~~~~
/usr/include/c++/14/bits/stl_map.h:335:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(std::map<_Key, _Tp, _Compare, _Alloc>&&) [with _Key = int; _Tp = long long int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, long long int> >]'
  335 |       operator=(map&&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:335:17: note:   no known conversion for argument 1 from 'int' to 'std::map<int, long long int>&&'
  335 |       operator=(map&&) = default;
      |                 ^~~~~
/usr/include/c++/14/bits/stl_map.h:349:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(std::initializer_list<std::pair<const _Key, _Val> >) [with _Key = int; _Tp = long long int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, long long int> >]'
  349 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:349:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::pair<const int, long long int> >'
  349 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:32:40: error: no matching function for call to 'max(long long int&, std::map<int, long long int>&)'
   32 |                                 ans=max(ans,D[V.first+w]);
      |                                     ~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:32:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::map<int, long long int>')
   32 |                                 ans=max(ans,D[V.first+w]);
      |                                     ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:32:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |                                 ans=max(ans,D[V.first+w]);
      |                                     ~~~^~~~~~~~~~~~~~~~~~