반응형
Notice
Recent Posts
Recent Comments
Link
불로구
백준 2798 (JAVA) - 블랙잭 본문
반응형
package 브루트포스;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class 블랙잭 {
static StringTokenizer st;
static int[] arr;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int idx = 0;
int result = 0;
st = new StringTokenizer(br.readLine(), " ");
arr = new int[N];
while(st.hasMoreElements()) {
arr[idx] = Integer.parseInt(st.nextToken());
idx++;
}
result = solution(M);
System.out.println(result);
}
static int solution(int max) {
int result = 0;
for(int i=0; i<arr.length - 2; i++) {
for(int j=i+1; j < arr.length -1; j++) {
for(int k=j+1; k<arr.length; k++) {
int sum = arr[i] + arr[j] + arr[k];
if(sum > result && sum <= max) {
result = sum;
}
}
}
}
return result;
}
}
반응형
'코딩테스트 > 백준' 카테고리의 다른 글
백준 7568 (JAVA) - 덩치 (0) | 2021.03.06 |
---|---|
백준 2231(JAVA) - 분해합 (0) | 2021.03.06 |
[백준 - 10816 ] - 숫자카드2( JAVA ) (0) | 2021.02.11 |
[백준 - 1920 ] - 수찾기 ( JAVA ) (0) | 2021.02.11 |
Comments