Language: C++

#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    ll N, gA, sA, bA, gB, sB, bB;
    cin >> N >> gA >> sA >> bA >> gB >> sB >> bB;
    if (gA <= gB && sA <= sB && bA <= bB) {
        int ans = 0;
        rep(g, N / gA + 1) {
            rep(s, (N - g * gA) / sA + 1) {
                int b = (N - g * gA - s * sA) / bA;
                ans = max(ans, N + g * (gB - gA) + s * (sB - sA) + b * (bB -bA));
            }
        }
        cout << ans << endl;
        return 0;
    }
    if (gA >= gB && sA >= sB && bA >= bB) {
        int ans = 0;
        rep(g, N / gB + 1) {
            rep(s, (N - g * gB) / sB + 1) {
                int b = (N - g * gB - s * sB) / bB;
                ans = max(ans, N + g * (gA - gB) + s * (sA - sB) + b * (bA -bB));
            }
        }
        cout << ans << endl;
        return 0;
    }
    int ans = 0;
    vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
    sort(v.begin(), v.end());
    if (v[1][0] < gB * sB * bB) {
        rep(i, N / v[0][1] + 1) {
            int M = N - i * v[0][1];
            int j = M / v[1][1];
            ans = max(ans, M - j * v[1][1] + i * v[0][2] + j * v[1][2]);
        }
        ans = ans - ans / v[2][2] + ans / v[2][2] * v[2][1];
    } else {
        int L = N - N / v[0][1] + N / v[0][1] * v[0][2];
        rep(k, 10000) {
            int i = L / v[2][1] - k;
            if (i < 0) break;
            int M = L - i * v[2][1];
            int j = M / v[1][1];
            ans = max(ans, M - j * v[1][1] + i * v[2][2] + j * v[1][2]);
        }
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:26: error: no matching function for call to 'max(int&, ll)'
   15 |                 ans = max(ans, N + g * (gB - gA) + s * (sB - sA) + b * (bB -bA));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:   template argument deduction/substitution failed:
a.cc:15:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   15 |                 ans = max(ans, N + g * (gB - gA) + s * (sB - sA) + b * (bB -bA));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:15:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   15 |                 ans = max(ans, N + g * (gB - gA) + s * (sB - sA) + b * (bB -bA));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:26:26: error: no matching function for call to 'max(int&, ll)'
   26 |                 ans = max(ans, N + g * (gA - gB) + s * (sA - sB) + b * (bA -bB));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:26:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   26 |                 ans = max(ans, N + g * (gA - gB) + s * (sA - sB) + b * (bA -bB));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
/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:26:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   26 |                 ans = max(ans, N + g * (gA - gB) + s * (sA - sB) + b * (bA -bB));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:33:39: warning: narrowing conversion of '((gA * sB) * bB)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                               ~~~~~~~~^~~~
a.cc:33:39: warning: narrowing conversion of '((gA * sB) * bB)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
a.cc:33:45: warning: narrowing conversion of 'gA' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                                             ^~
a.cc:33:45: warning: narrowing conversion of 'gA' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
a.cc:33:49: warning: narrowing conversion of 'gB' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                                                 ^~
a.cc:33:49: warning: narrowing conversion of 'gB' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
a.cc:33:63: warning: narrowing conversion of '((gB * sA) * bB)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                                                       ~~~~~~~~^~~~
a.cc:33:63: warning: narrowing conversion of '((gB * sA) * bB)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
a.cc:33:69: warning: narrowing conversion of 'sA' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                                                                     ^~
a.cc:33:69: warning: narrowing conversion of 'sA' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
a.cc:33:73: warning: narrowing conversion of 'sB' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                                                                         ^~
a.cc:33:73: warning: narrowing conversion of 'sB' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
a.cc:33:87: warning: narrowing conversion of '((gB * sB) * bA)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                                                                               ~~~~~~~~^~~~
a.cc:33:87: warning: narrowing conversion of '((gB * sB) * bA)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
a.cc:33:93: warning: narrowing conversion of 'bA' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                                                                                             ^~
a.cc:33:93: warning: narrowing conversion of 'bA' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
a.cc:33:97: warning: narrowing conversion of 'bB' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |     vector<vector<int>> v = {{gA * sB * bB, gA, gB}, {gB * sA * bB, sA, sB}, {gB * sB * bA, bA, bB}};
      |                                                                                                 ^~
a.cc:33:97: warning: narrowing conversion of 'bB' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]