Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
const ll inf = (1ll<<60);

int n, Ma, Mb;

int a[50];
int b[50];
int c[50];

void in(){
	read(n, Ma, Mb);
	for(int i=0; i<n; ++i) read(a[i], b[i], c[i]);
}

int hn;

map<ll, ll> ml, mr;

ll ans=inf;

void dfs0(int p=0, int sa=0, int sb=0, int sc=0){
	if(p == hn){
		ll x=sb*1LL*Ma - sa*1LL*Mb;
		if(ml.find(x) == ml.end()) ml[x]=inf;
		ml[x]=min(ml[x], ll(sc));
		if(sb*1LL*Ma == sa*1LL*Mb && sa){
			ans=min(ans, sc);
		}
		return;
	}
	dfs0(p+1, sa, sb, sc);
	dfs0(p+1, sa+a[p], sb+b[p], sc+c[p]);
}

void dfs1(int p=hn, int sa=0, int sb=0, int sc=0){
	if(p == n){
		ll x=-(sb*1LL*Ma - sa*1LL*Mb);
		if(ml.find(x) != ml.end() && sc+ml[x])
			ans=min(ans, sc+ml[x]);
		return;
	}
	dfs1(p+1, sa, sb, sc);
	dfs1(p+1, sa+a[p], sb+b[p], sc+c[p]);
}

int main()
{
    in();
    hn=n/2;
    dfs0();
    dfs1();
    if(ans == inf) ans=-1;
    printf("%lld\n", ans);
    return 0;
}


Compiler output:
a.cc: In function 'void dfs0(int, int, int, int)':
a.cc:35:32: error: no matching function for call to 'min(ll&, int&)'
   35 |                         ans=min(ans, sc);
      |                             ~~~^~~~~~~~~
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: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:32: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   35 |                         ans=min(ans, sc);
      |                             ~~~^~~~~~~~~
/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
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:35:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   35 |                         ans=min(ans, sc);
      |                             ~~~^~~~~~~~~