代码:
import java.util.Scanner;
public class Class {
public static void main(String[] args) {
int n=new Scanner(System.in).nextInt();
int k=new Scanner(System.in).nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i]=new Scanner(System.in).nextInt();
}
for (int i = 1; i <= k; i++) {
a[max(a)]--;
a[min(a)]++;
}
System.out.println(a[max(a)]-a[min(a)]);
}
private static int max(int[] a) {
int max = 0;
for (int i = 0; i < a.length-1; i++) {
if(a[i+1]>a[i]){
max = i+1;
}
}
return max;
}
private static int min(int[] a) {
int min = 0;
for (int i = 0; i < a.length-1; i++) {
if(a[i+1]<a[i]){
min = i+1;
}
}
return min;
}
}