코딩왕랄프👊🏻

[백준] 2798번 블랙잭 본문

백준

[백준] 2798번 블랙잭

hyerm_2 2022. 4. 12. 14:47
반응형
SMALL

https://www.acmicpc.net/problem/2798

 

2798번: 블랙잭

첫째 줄에 카드의 개수 N(3 ≤ N ≤ 100)과 M(10 ≤ M ≤ 300,000)이 주어진다. 둘째 줄에는 카드에 쓰여 있는 수가 주어지며, 이 값은 100,000을 넘지 않는 양의 정수이다. 합이 M을 넘지 않는 카드 3장

www.acmicpc.net

 

 

import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
		int[] card=new int[100];
		int a=sc.nextInt();
		int b=sc.nextInt();
		int total=0;
		
		for(int i=0;i<a;i++) 
			card[i]=sc.nextInt();
		
		for(int i=0;i<a-2;i++) {
			for(int j=i+1;j<a-1;j++) {
				for(int k=j+1;k<a;k++) {
					if(b>=card[i]+card[j]+card[k]&&b-(card[i]+card[j]+card[k])<b-total)	total=card[i]+card[j]+card[k];
				}
			}
		}
		System.out.println(total);
  }
}
반응형
LIST

'백준' 카테고리의 다른 글

[백준] 1189번 컴백홈  (0) 2023.07.25
[백준] 2644번 촌수계산  (0) 2023.07.25
[백준] 1065번 한수  (0) 2022.04.12
[백준] 4673번 셀프 넘버  (0) 2022.04.12
[백준] 2231번 분해합  (0) 2022.04.11