-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sohyundoh
committed
Mar 25, 2022
1 parent
5fcda78
commit d1e56b5
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
int card[300]; // 카드값을 입력받을 배열 | ||
int main() { | ||
int n, tn; | ||
cin >> n >> tn; | ||
int max = 0; | ||
for (int i = 0; i < n; i++) { | ||
cin >> card[i]; | ||
} | ||
for (int j = 0; j < n; j++) { | ||
for (int k = 0; k < n; k++) { | ||
for (int i = 0; i < n; i++) { | ||
if (i == j || j == k || i == k) { //같은 카드를 뽑을 수는 없음 | ||
continue; | ||
} | ||
int sum = card[i] + card[j] + card[k]; //카드 값을 일일이 다 계산 시간복잡도: O(n^3) | ||
if (sum > max && sum <= tn) { //입력받은 값보다 작은데 가장 큰 값 찾기 | ||
max = sum; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
cout << max; | ||
} |