Language: C++

#include <bits/stdc++.h>

using ll = long long;
using pr = pair<ll, ll>;

ll KnapsackDP(vector<pr>&sack, int w) {
	vector<vector<ll>>dp(sack.size() + 1, vector<ll>(w + 1, 0));
	sort(sack.begin(), sack.end());
 
	ll m = 0;
 
	for (int i = 0; i < sack.size(); ++i)
		for (int j = sack[i].first; j <= w; ++j) {
			dp[i + 1][j] = max(dp[i][j], dp[i][j - sack[i].first] + sack[i].second);
			m = max(m, dp[i + 1][j]);
		}
 
	return m;
}
 
int main() {
	int N, W, w, c;
	cin >> N >> W;
	vector<pr>sack;
	for (int i = 0; i < N; ++i) {
		cin >> w >> c;
		sack.push_back({ w, c });
	}
	cout << KnapsackDP(sack, W) << endl;
}

Compiler output:
a.cc:4:12: error: 'pair' does not name a type
    4 | using pr = pair<ll, ll>;
      |            ^~~~
a.cc:6:15: error: 'vector' was not declared in this scope
    6 | ll KnapsackDP(vector<pr>&sack, int w) {
      |               ^~~~~~
a.cc:6:15: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:6:22: error: 'pr' was not declared in this scope
    6 | ll KnapsackDP(vector<pr>&sack, int w) {
      |                      ^~
a.cc:6:26: error: 'sack' was not declared in this scope
    6 | ll KnapsackDP(vector<pr>&sack, int w) {
      |                          ^~~~
a.cc:6:32: error: expected primary-expression before 'int'
    6 | ll KnapsackDP(vector<pr>&sack, int w) {
      |                                ^~~
a.cc:6:37: error: expression list treated as compound expression in initializer [-fpermissive]
    6 | ll KnapsackDP(vector<pr>&sack, int w) {
      |                                     ^
a.cc: In function 'int main()':
a.cc:23:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   23 |         cin >> N >> W;
      |         ^~~
      |         std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:24:9: error: 'vector' was not declared in this scope
   24 |         vector<pr>sack;
      |         ^~~~~~
a.cc:24:9: note: suggested alternatives:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:24:16: error: 'pr' was not declared in this scope
   24 |         vector<pr>sack;
      |                ^~
a.cc:24:19: error: 'sack' was not declared in this scope
   24 |         vector<pr>sack;
      |                   ^~~~
a.cc:29:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   29 |         cout << KnapsackDP(sack, W) << endl;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:29:27: error: 'KnapsackDP' cannot be used as a function
   29 |         cout << KnapsackDP(sack, W) << endl;
      |                 ~~~~~~~~~~^~~~~~~~~
a.cc:29:40: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   29 |         cout << KnapsackDP(sack, W) << endl;
      |                                        ^~~~
      |                                        std::endl
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~