-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2798.java
More file actions
37 lines (29 loc) · 678 Bytes
/
Copy path2798.java
File metadata and controls
37 lines (29 loc) · 678 Bytes
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
import java.util.Scanner;
public class Main {
int BlackJack(int M, int[] arr) {
int max=0;
for(int i=0; i<arr.length-2; i++) {
for(int j=i+1; j<arr.length-1; j++) {
for(int z=j+1; z<arr.length; z++) {
int sum=arr[i]+arr[j]+arr[z];
if(sum<=M) {
if(max<=sum)
max=sum;
}
}
}
}
return max;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Main Main = new Main();
int N = scanner.nextInt();
int M = scanner.nextInt();
int arr[]= new int[N];
for(int i=0; i<N; i++)
arr[i]=scanner.nextInt();
System.out.println(Main.BlackJack(M,arr));
scanner.close();
}
}