forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2198.cpp
More file actions
40 lines (35 loc) · 641 Bytes
/
Copy path2198.cpp
File metadata and controls
40 lines (35 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
int N, M;
int cards[101];
bool include[101];
int ans = 0;
void find(int idx, int selected) {
if (idx == N+1 && selected == 3) {
int sum = 0;
for (int i = 1; i <= N; i++) {
if (include[i]) {
sum += cards[i];
//cout << "1 ";
}
//else cout << "0 ";
}
//cout << "\n";
if (sum > ans && M >= sum) ans = sum;
}
if (idx == N + 1 || selected > 3) return;
include[idx] = true;
find(idx + 1, selected + 1);
include[idx] = false;
find(idx + 1, selected);
}
int main()
{
int i;
cin >> N >> M;
for (i = 1; i <= N; i++) {
cin >> cards[i];
}
find(1, 0);
cout << ans;
}