Language: C++

#include <iostream>
#include <cmath>
using namespace std;

const int INF = 5000;

int main() {

        int dp[40][405][405];
        for (int i=0; i<40; ++i) {
                for (int j=0; j<405; ++j) {
                        for (int k=0; k<405; ++k) {
                                dp[i][j][k] = INF;
                        }
                }
        }
        dp[0][0][0] = 0;

        int a[41], b[41], c[41];
        for (int i=0; i<n; ++i) {
                cin >> a[i] >> b[i] >> c[i];
        }

        int n, ma, mb;
        cin >> n >> ma >> mb;

        for (int i=0; i<n; ++i) {
                // int a, b, c;
                // cin >> a >> b >> c;
                for (int j=0; j<405; ++j) {
                        for (int k=0; k<405; ++k) {

                                if (dp[i][j][k]<INF) {
                                        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                                        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c);
                                }

                        }
                }
        }

        int ans = INF;
        for (int i=1; i*ma<=405 && i*mb<=405; ++i) {
                ans = min(ans, dp[n][i*ma][i*mb]);
        }
        if (ans<INF) {
                cout << ans << endl;
        } else {
                cout << -1 << endl;
        }
        return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:25: error: 'n' was not declared in this scope
   20 |         for (int i=0; i<n; ++i) {
      |                         ^
a.cc:35:70: error: no matching function for call to 'min(int&, int*)'
   35 |                                         dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c);
      |                                                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:35:70: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'int*')
   35 |                                         dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c);
      |                                                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided