题目:
解答:
vector<int> str2vint(string str, char split)
{
int start = 0;
vector<int> res;
for (int i = 0; i < str.size(); i++)
{
if (str[i] == split)
{
res.push_back(stoi(str.substr(start, i - start)));
start = i + 1;
}
}
res.push_back(stoi(str.substr(start, str.size() - start)));
return res;
}
int main() {
string str;
getline(cin, str);
vector<int> res = str2vint(str, ',');
int money;
cin >> money;
sort(res.begin(), res.end());
int max = 0;
for (int i = 0; i < res.size() - 2; ++i)
{
int sum = 0;
for (int j = i; j < 3; j++)
{
if ((sum + res[j]) > money)
{
break;
}
sum += res[j];
}
if (sum > max)
{
max = sum;
}
}
cout << max << endl;
return 0;
}