Language: C++

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

using namespace std;

#define vital first
#define cal second
#define happy first
#define N 100001

int main(){
	int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
	vector<pair<int, int> > train(T);
	vector<pair<int, int> > donut(N);
	vector<vector<int> > dp_VtoC(U+1, vector<int>(S+1));
	int dp_CtoH[N];
	vector<int> dp_VtoH(S+1);
	vector<vector<int> > dp(D+1, vector<int>(S+1));

	for (int i = 0; i < T; i++) { cin >> train[i].vital >> train[i].cal; }
	for (int i = 0; i < N; i++) { cin >> donut[i].happy >> donut[i].cal; }

	for (int i = 0; i < U+1; i++)
		for (int j = 0; j < S+1; j++)
			dp_VtoC[i][j] = -1; 
	dp_VtoC[0][0] = 0;
	for (int i = 0; i < T; i++) {
		for (int j = U-1; j >= 0; j--) {
			for (int k = S; k >= 0; k--) {
				if (dp_VtoC[j][k] != -1 && k+train[i].vital <= S) {
					dp_VtoC[j+1][k+train[i].vital] = max(dp_VtoC[j][k]+train[i].cal, dp_VtoC[j+1][k+train[i].vital]);
				}
			}
		}
	}
	for (int i = 0; i < N; i++) dp_CtoH[i] = -1;
	dp_CtoH[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (dp_CtoH[j] != -1 && j + donut[i].cal < N) {
				dp_CtoH[j+donut[i].cal] = max(dp_CtoH[j+donut[i].cal], dp_CtoH[j]+donut[i].happy);
			}
		}
	}
	for (int i = 0; i < S+1; i++) dp_VtoH[i] = -1;
	for (int i = 0; i < S+1; i++) {
		if (dp_VtoC[U][i] != -1) {
			for (int j = dp_VtoC[U][i]; j >= 0; j--) {
				dp_VtoH[i] = max(dp_VtoH[i], dp_CtoH[j]);
			}
		}
	}

	for (int i = 0;  i < U+1; i++)
		for (int j = 0; j < S+1; j++)
			dp[i][j] = -1;
	dp[0][S] = 0;
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < S+1; j++) {
			if (dp[i][j] != -1) {
				for (int k = 0; k < S+1; k++) {
					if (dp_VtoH[k] != -1 && j-k >= 0) {
						dp[i+1][j-k] = max(dp[i+1][j-k], dp[i][j]+dp_VtoH[k]);
					}
				}
			}
		}
		for (int j = S; j >= 0; j--) {
			int tmp = min(j+O, S);
			dp[i+1][tmp] = dp[i+1][j];
			//dp[i][j] = -1;
		}
	}

	int res = 0;
	for (int i = 0; i < S+1; i++) { res = max(res, dp[D][i]); }
	if (res) {
		cout << res << endl;
	} else {
		cout << "-1" << endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:11: error: expected unqualified-id before numeric constant
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:22: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                      ^
a.cc:14:50: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and 'int')
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                               ~~~~~~~~~~~~~~~~~~ ^~
      |                                             |
      |                                             std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/iostream:42,
                 from a.cc:1:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: warning: overflow in conversion from 'int' to 'short int' changes value from '100001' to '-31071' [-Woverflow]
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: warning: unsigned conversion from 'int' to 'short unsigned int' changes value from '100001' to '34465' [-Woverflow]
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'short unsigned int&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'unsigned int&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'long int&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  199 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:199:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  203 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:203:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'long long unsigned int&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:219:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  219 |       operator>>(float& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:219:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'float&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:223:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  223 |       operator>>(double& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:223:7: note:   conversion of argument 1 would be ill-formed:
a.cc:11:11: error: cannot bind non-const lvalue reference of type 'double&' to a value of type 'int'
   11 | #define N 100001
      |           ^~~~~~
a.cc:14:53: note: in expansion of macro 'N'
   14 |         int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
      |                                                     ^
/usr/include/c++/14/istream:227:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  227 |       operator>>(long double& __f)
      |       ^~~~~~~~
/usr/include/c++/14/is