반응형
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int card[101];
vector<int> idx;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
int max = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> card[i];
if (i < 3)
idx.push_back(1);
else
idx.push_back(0);
}
sort(idx.begin(), idx.end());
do
{
int total = 0;
for (int i = 0; i < idx.size(); i++)
{
if (idx[i] == 1)
{
total += card[i];
}
}
if (max < total && total <= m)
max = total;
} while (next_permutation(idx.begin(), idx.end()));
cout << max << "\n";
return 0;
}
반응형
'코딩테스트(Coding Test) > 백준' 카테고리의 다른 글
[백준][C++]#10989 수정렬하기 (0) | 2022.10.10 |
---|---|
[백준][C++]#2609 최대공약수와 최대공배수 (0) | 2022.10.09 |
[백준][C++]#2309 일곱 난쟁이 (0) | 2022.09.25 |
[C++|헤더] bits/stdc++.h (0) | 2022.09.25 |
[C++]입출력 속도 개선 (0) | 2022.09.20 |