Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)

template<typename T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U & u, const V... v) { for (auto& e : u)fill_v<T>(e, v...); }

template <typename T>
std::string printVector(const std::vector<T>& data)
{
	std::stringstream ss;
	std::ostream_iterator<T> out_it(ss, ", ");
	ss << "[";
	std::copy(data.begin(), data.end() - 1, out_it);
	ss << data.back() << "]";
	return ss.str();
}

constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	int n; cin >> n;
	int a[3], b[3];
	cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1] >> b[2];
	// Bで交換した場合に限り、その好感したドングリをB -> Aの交換にも使える

	vector<ll> dp(n + 1);
	iota(dp.begin(), dp.end(), 0);
	rep(i, 0, n + 1)
		rep(j, 0, 3) 
			if (i >= a[j]) dp[i] = max(dp[i], dp[i - a[j]] + b[j]);

	n = dp[n];
	dp.clear();
	dp.assign(n + 1, 0);
	iota(dp.begin(), dp.end(), 0);
	rep(i, 0, n + 1)
		rep(j, 0, 3)
		if (i >= b[j]) dp[i] = max(dp[i], dp[i - b[j]] + a[j]);
	cout << dp[n] << endl;
	return 0;
}

Compiler output:
a.cc: In function 'std::string printVector(const std::vector<_Tp>&)':
a.cc:23:14: error: 'ostream_iterator' is not a member of 'std'
   23 |         std::ostream_iterator<T> out_it(ss, ", ");
      |              ^~~~~~~~~~~~~~~~
a.cc:6:1: note: 'std::ostream_iterator' is defined in header '<iterator>'; this is probably fixable by adding '#include <iterator>'
    5 | #include <numeric>
  +++ |+#include <iterator>
    6 | using namespace std;
a.cc:23:32: error: expected primary-expression before '>' token
   23 |         std::ostream_iterator<T> out_it(ss, ", ");
      |                                ^
a.cc:23:34: error: there are no arguments to 'out_it' that depend on a template parameter, so a declaration of 'out_it' must be available [-fpermissive]
   23 |         std::ostream_iterator<T> out_it(ss, ", ");
      |                                  ^~~~~~
a.cc:23:34: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:24:12: error: no match for 'operator<<' (operand types are 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} and 'const char [2]')
   24 |         ss << "[";
      |         ~~ ^~ ~~~
      |         |     |
      |         |     const char [2]
      |         std::stringstream {aka std::__cxx11::basic_stringstream<char>}
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/string_view:763:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, basic_string_view<_CharT, _Traits>)'
  763 |     operator<<(basic_ostream<_CharT, _Traits>& __os,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:763:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/bits/basic_string.h:4077:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 4077 |     operator<<(basic_ostream<_CharT, _Traits>& __os,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4077:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
   24 |         ss << "[";
      |               ^~~
In file included from /usr/include/c++/14/bits/memory_resource.h:38,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/cstddef:125:5: note: candidate: 'template<class _IntegerType> constexpr std::__byte_op_t<_IntegerType> std::operator<<(byte, _IntegerType)'
  125 |     operator<<(byte __b, _IntegerType __shift) noexcept
      |     ^~~~~~~~
/usr/include/c++/14/cstddef:125:5: note:   template argument deduction/substitution failed:
a.cc:24:9: note:   cannot convert 'ss' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'std::byte'
   24 |         ss << "[";
      |         ^~
In file included from /usr/include/c++/14/bits/ios_base.h:46:
/usr/include/c++/14/system_error:339:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const error_code&)'
  339 |     operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
      |     ^~~~~~~~
/usr/include/c++/14/system_error:339:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:563:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, _CharT)'
  563 |     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:563:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:573:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char)'
  573 |     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:573:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:579:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char)'
  579 |     operator<<(basic_ostream<char, _Traits>& __out, char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:579:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:590:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char)'
  590 |     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:590:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:595:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char)'
  595 |     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:595:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:654:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const _CharT*)'
  654 |     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:654:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
   24 |         ss << "[";
      |               ^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:307:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const char*)'
  307 |     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
      |     ^~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:307:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:671:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, const char*)'
  671 |     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:671:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:684:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, const signed char*)'
  684 |     operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:684:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:689:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, const unsigned char*)'
  689 |     operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:689:5: note:   template argument deduction/substitution failed:
a.cc:24:15: note:   'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
   24 |         ss << "[";
      |               ^~~
/usr/include/c++/14/ostream:810:5: note: candidate: 'template<class _Ostream, class _Tp> _Ostream&& std::operator<<(_Ostream&&, const _Tp&)'
  810 |     oper