코드
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
static int n;
static int[] cities;
static int budget;
static int max = -1;
public static void main(String[] args) {
input();
int result = func();
System.out.println(result == 1_000_000_001 ? max : result);
}
static void input() {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
cities = new int[n];
for (int i = 0; i < n; ++i) {
cities[i] = sc.nextInt();
max = Math.max(max, cities[i]);
}
budget = sc.nextInt();
sc.close();
}
static int func() {
long left = 1L;
long right = 1_000_000_001L;
int result = -1;
while (right >= left) {
int mid = (int)((left + right) / 2);
if (budget >= getRequiredBudget(mid)) {
result = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
return result;
}
static int getRequiredBudget(int limit) {
int sum = 0;
for (int i : cities) {
sum += Math.min(i, limit);
}
return sum;
}
}