#include <cstdio>
#include <cstring>
#include <string>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> fruits;
bool cmp(int a, int b)
{
return a > b;
}
int change(int leftValue, int useCnt)
{
if (leftValue < 0)
return -1;
if (leftValue == 0)
return useCnt;
for (vector<int>::iterator it = fruits.begin(); it != fruits.end(); ++it)
{
int value = *it;
int min = change(leftValue - value, useCnt + 1);
if (min > 0) return min;
}
return -1;
}
int strToInt(string str)
{
str += '\0';
int value = 0;
char numStr[100];
strcpy(numStr, str.c_str());
sscanf(numStr, "%d", &value);
return value;
}
int main()
{
string inputStr;
int totalValue;
cin >> inputStr >> totalValue;
int len = inputStr.length();
string temp = "";
for (int i = 0; i < len; ++i)
{
if (inputStr[i] != ',')
{
temp += inputStr[i];
}
else
{
fruits.push_back(strToInt(temp));
temp = "";
}
}
if (temp != "")
{
fruits.push_back(strToInt(temp));
temp = "";
}
int useCnt = 0;
sort(fruits.begin(), fruits.end(), cmp);
useCnt = change(totalValue, 0);
printf("%d\n", useCnt);
fruits.clear();
//system("pause");
return 0;
}
20%