Language: C++

#include<iostream>
#include<vector>
using namespace std;
main(){
  int n,ga,gb,sa,sb,ba,bb;
  cin>>n>>ga>>sa>>ba>>gb>>sb>>bb;
  vector<int> dpab(n+1,0);
  for(int i=1;i<=n;++i)dpab[i]=max({
    i-ga>=0?dpab[i-ga]+gb:0,
    i-sa>=0?dpab[i-sa]+sb:0,
    i-ba>=0?dpab[i-ba]+bb:0
  });
  vector<int> dpba(dpab[n]+1,0);
  for(int i=1;i<=dpab[n];++i)dpba[i]=max({
    i-gb>=0?dpba[i-gb]+ga:0,
    i-sb>=0?dpba[i-sb]+sa:0,
    i-bb>=0?dpba[i-bb]+ba:0
  });
  cout<<dpba[dpab[n]];
}

Compiler output:
a.cc:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:8:35: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
    8 |   for(int i=1;i<=n;++i)dpab[i]=max({
      |                                ~~~^~
    9 |     i-ga>=0?dpab[i-ga]+gb:0,
      |     ~~~~~~~~~~~~~~~~~~~~~~~~       
   10 |     i-sa>=0?dpab[i-sa]+sb:0,
      |     ~~~~~~~~~~~~~~~~~~~~~~~~       
   11 |     i-ba>=0?dpab[i-ba]+bb:0
      |     ~~~~~~~~~~~~~~~~~~~~~~~        
   12 |   });
      |   ~~                               
In file included from /usr/include/c++/14/string:51,
                 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/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:   candidate expects 2 arguments, 1 provided
/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, 1 provided
a.cc:14:41: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   14 |   for(int i=1;i<=dpab[n];++i)dpba[i]=max({
      |                                      ~~~^~
   15 |     i-gb>=0?dpba[i-gb]+ga:0,
      |     ~~~~~~~~~~~~~~~~~~~~~~~~             
   16 |     i-sb>=0?dpba[i-sb]+sa:0,
      |     ~~~~~~~~~~~~~~~~~~~~~~~~             
   17 |     i-bb>=0?dpba[i-bb]+ba:0
      |     ~~~~~~~~~~~~~~~~~~~~~~~              
   18 |   });
      |   ~~                                     
/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:   candidate expects 2 arguments, 1 provided
/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, 1 provided