https://www.acmicpc.net/problem/2798
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt(), m=s.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=s.nextInt();
}
int max=0;
int sum=0;
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++){
sum=0;
sum=arr[i]+arr[j]+arr[k];
if(sum<=m && max<=sum) max=sum;
}
}
}
System.out.print(max);
}
}