코드
import java.io.*;
import java.util.*;
public class Main {
static int n;
static int m;
static int[] trees;
static int result;
public static void main(String[] args) {
input();
func();
System.out.println(result);
}
static void input() {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
trees = new int[n];
sc.nextLine();
int i = 0;
for (String s : sc.nextLine().split(" ")) {
trees[i++] = Integer.parseInt(s);
}
sc.close();
}
static void func() {
int left = 0;
int right = 1_000_000_000;
while (right >= left) {
int mid = (left + right) / 2;
if (getTotalLength(mid) >= m) {
result = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
}
static long getTotalLength(int cut) {
long sum = 0L;
for (int i : trees) {
if (i > cut) {
sum += i - cut;
}
}
return sum;
}
}