Skip to content

Commit 021078a

Browse files
authored
Merge pull request #1423 from AlgorithmWithGod/khj20006
[20251116] BOJ / G5 / 가장 큰 값 / 권혁준
2 parents 33ef3d4 + 5168789 commit 021078a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int N, M, a[20]{}, ans = -1234567;
6+
7+
int main() {
8+
cin.tie(0)->sync_with_stdio(0);
9+
10+
cin >> N >> M;
11+
for (int i = 0; i < N; i++) cin >> a[i];
12+
13+
for (int i = 1; i < (1 << N); i++) {
14+
int sum = 0, group = 0, cnt = 0;
15+
for (int j = 0; j < N; j++) {
16+
if ((i & (1 << j))) {
17+
cnt++;
18+
if ((!j || !(i & (1 << (j - 1))))) group++;
19+
}
20+
sum += (i & (1 << j)) ? a[j] : 0;
21+
}
22+
if (group <= M && cnt >= M) ans = max(ans, sum);
23+
}
24+
cout << ans;
25+
26+
}
27+
```

0 commit comments

Comments
 (0)