-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
63f9597
commit d4ff1bd
Showing
1 changed file
with
42 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,42 @@ | ||
## [black jack](https://www.acmicpc.net/problem/2798) | ||
|
||
### Problem | ||
주어진 카드 중 3장을 골라, 그 합이 m 가장 가까운 값을 리턴 | ||
|
||
### Solve | ||
```java | ||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
|
||
int n = sc.nextInt(); | ||
int m = sc.nextInt(); | ||
int[] cards = new int[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
cards[i] = sc.nextInt(); | ||
} | ||
|
||
int max = 0; | ||
outline : for (int i = 0; i < n-2; i++) { | ||
for (int j = i+1; j < n-1; j++) { | ||
for (int k = j+1; k < n; k++) { | ||
|
||
int sum = cards[i] + cards[j] + cards[k]; | ||
if(sum <= m) { | ||
max = Math.max(max, sum); | ||
} | ||
|
||
if(max == m) { | ||
break outline; | ||
} | ||
} | ||
} | ||
} | ||
|
||
System.out.println(max); | ||
} | ||
} | ||
``` |