백준 2798: 블랙잭
2023. 1. 31. 21:01ㆍ개인공부/코딩테스트
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
41
42
43
44
45
46
47
48
49
|
#include <iostream>
using namespace std;
int main()
{
int Card = 0;
int Max = 0;
cin >> Card >> Max;
int* CardNumber = new int[Card];
for (int i = 0; i < Card; ++i)
{
cin >> CardNumber[i];
}
int SelectCard[3] = {};
int ApproachMax = Max;
for (int i = 0; i < Card; ++i)
{
SelectCard[0] = CardNumber[i];
for (int j = i + 1; j < Card; ++j)
{
SelectCard[1] = CardNumber[j];
for (int k = j + 1; k < Card; ++k)
{
SelectCard[2] = CardNumber[k];
int result = SelectCard[0] + SelectCard[1] + SelectCard[2];
if (Max == result)
{
cout << Max;
return 0;
}
else if (Max < result)
{
continue;
}
else if (ApproachMax > Max - result)
ApproachMax = Max - result;
}
}
}
cout << Max - ApproachMax;
}
|
cs |
'개인공부 > 코딩테스트' 카테고리의 다른 글
백준 1436: 영화감독 숌 (0) | 2023.01.31 |
---|---|
백준 2231: 분해합 (0) | 2023.01.31 |
백준 2108: 통계학 (0) | 2023.01.31 |
백준 10814: 나이순 정렬 (0) | 2023.01.30 |
백준 1181: 단어 정렬 (0) | 2023.01.30 |