Language: C++

#include<iostream>
#include<sstream>
#include<fstream>
#include<cstring>/*The header <string> and
<string.h> does not contain the useful
function 'memset' and 'memcpy'.*/
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<utility>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
vector<pair<pair<int,int>,int> > X;
int init=INT_MAX,ans=INT_MAX,dp[50],N,A,B;
void dfs(int pos,int a,int b,int c)
{
	if(pos==X.size())
	{
		if(a==A&&b==B)
			ans=min(ans,c);
		return ;
	}
	dfs(pos+1,a,b,c);
	if(a+X[pos].first.first<=A&&b+X[pos].first.second<=B)
		dfs(pos+1,a+X[pos].first.first,b+X[pos].first.second,c+X[pos].second);
	return ;
}
int main()
{
	cin.tie();
	cout.tie();
	ios_base::sync_with_stdio(false);
	cin>>N>>A>>B;
	for(int i=0;i<N;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		if(x*B==y*A)
			init=min(init,z);
		else	X.push_back(make_pair(make_pair(x,y),z));
	}
	sort(X.begin(),X.end());
	int Ai=A,Bi=B;
	while(A<=10&&B<=10)
	{
		vector<pair<pair<int,int>,int> > V;
		for(int i=0;i<X.size();i++)
			if(X[i].first.first<=A&&X[i].first.second<=B)
				V.push_back(X[i]);
		swap(V,X);
		dfs(0,0,0,0);
		A+=Ai;
		B+=Bi;
		swap(V,X);
	}
	cout<<(init==INT_MAX&&ans==INT_MAX?-1:min(init,ans))<<endl;
	return 0;
}


Compiler output:
a.cc:23:10: error: 'INT_MAX' was not declared in this scope
   23 | int init=INT_MAX,ans=INT_MAX,dp[50],N,A,B;
      |          ^~~~~~~
a.cc:21:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   20 | #include<cstdio>
  +++ |+#include <climits>
   21 | using namespace std;
a.cc: In function 'void dfs(int, int, int, int)':
a.cc:28:23: error: 'A' was not declared in this scope
   28 |                 if(a==A&&b==B)
      |                       ^
a.cc:28:29: error: 'B' was not declared in this scope
   28 |                 if(a==A&&b==B)
      |                             ^
a.cc:29:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   29 |                         ans=min(ans,c);
      |                         ^~~
      |                         abs
a.cc:33:34: error: 'A' was not declared in this scope
   33 |         if(a+X[pos].first.first<=A&&b+X[pos].first.second<=B)
      |                                  ^
a.cc:33:60: error: 'B' was not declared in this scope
   33 |         if(a+X[pos].first.first<=A&&b+X[pos].first.second<=B)
      |                                                            ^
a.cc: In function 'int main()':
a.cc:42:14: error: 'N' was not declared in this scope
   42 |         cin>>N>>A>>B;
      |              ^
a.cc:42:17: error: 'A' was not declared in this scope
   42 |         cin>>N>>A>>B;
      |                 ^
a.cc:42:20: error: 'B' was not declared in this scope
   42 |         cin>>N>>A>>B;
      |                    ^
a.cc:65:22: error: 'INT_MAX' was not declared in this scope
   65 |         cout<<(init==INT_MAX&&ans==INT_MAX?-1:min(init,ans))<<endl;
      |                      ^~~~~~~
a.cc:65:22: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:65:31: error: 'ans' was not declared in this scope; did you mean 'abs'?
   65 |         cout<<(init==INT_MAX&&ans==INT_MAX?-1:min(init,ans))<<endl;
      |                               ^~~
      |                               abs