# A KETO DIET

### A KETO DIET

Tokita Ohma plans to start a keto diet. His automated kitchen can prepare NN types of food items. The ii-th food item has pipi grams of protein, fifi grams of fat, and cici grams of carbohydrates. Ohma wants to consume at least PP grams of protein and FF grams of fat each day while minimizing the carbohydrates he consumes. He also won't eat the same food item twice in the same day.

What food items should Ohma eat in a day so that he minimizes the carbohydrates he consumes and gets at least PP grams of protein and FF grams of fat. If it is not possible, output −1−1.

Input

Two integers P,FP,F on the first line.

One integer NN on the second line.

NN lines follow. Three integers pi,fi,cipi,fi,ci on the (i+2)(i+2)-th line.

Constraints

1≤N≤10001≤N≤1000

1≤P,F≤2501≤P,F≤250

1≤pi,fi,ci≤2501≤pi,fi,ci≤250

Output

One integer --- the minimum carbohydrates Ohma will end up having to consume in order to get at least PP grams of protein and FF grams of fat. If it is impossible to meet that requirement, output −1−1.

Example 1

Input
50 50
5
8 43 27
32 2 21
8 34 48
31 29 36
23 2 11

Output
74

 #include using namespace std;#define int            long long int#define F              first#define S              second#define pb             push_back#define si             set #define vi             vector #define pii            pair #define vpi            vector #define vpp            vector >#define mii            map #define mpi            map #define spi            set #define endl           "\n"#define sz(x)          ((int) x.size())#define all(p)         p.begin(), p.end()#define double         long double#define que_max        priority_queue #define que_min        priority_queue >#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)#define print(a)       for(auto x : a) cout << x << " "; cout << endl#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endlinline int power(int a, int b){  int x = 1;  while (b)  {    if (b & 1) x *= a;    a *= a;    b >>= 1;  }  return x;}template void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }template void __f (const char* names, Arg1&& arg1, Args&&... args){  const char* comma = strchr (names + 1, ',');  cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);}const int N = 200005;void solve() {int n,p,f;cin>>p>>f>>n;vector>food;int sump=0,sumf=0;for (int i = 0; i < n; i++){  int x,y,z;  cin>>x>>y>>z;  food.push_back({x,y,z});  sump+=x;  sumf+=y;}if(sump>>dp(n+1,vector>(p+1,vector(f+1,INT_MAX)));dp[n]=0;for (int i = n - 1; i >= 0; i--){  for (int j = 0; j <=p; j++)  {    for (int k = 0; k <=f; k++)    {      int temp=dp[i+1][max(0LL,j-food[i])][max(0LL,k-food[i])]+food[i];      dp[i][j][k]=min(dp[i+1][j][k],temp);    }      }  }cout<> t;   while (t--) solve();  return 0;}