import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] a = new int[n];
PriorityQueue<Tower> min = new PriorityQueue<>(new Comparator<Tower>() {
@Override
public int compare(Tower o1, Tower o2) {
return o1.value-o2.value;
}
});
PriorityQueue<Tower> max = new PriorityQueue<>(new Comparator<Tower>() {
@Override
public int compare(Tower o1, Tower o2) {
return o2.value-o1.value;
}
});
for (int i = 0; i < n; i++) {
int ele = sc.nextInt();
Tower t = new Tower(i+1,ele);
min.offer(t);
max.offer(t);
}
int m=0;
List<Integer> list1 = new ArrayList<>();
List<Integer> list2 = new ArrayList<>();
for(int i=0;i<k&&(max.peek().value-min.peek().value)>1;i++){
m++;
Tower ma = max.poll();
ma.value--;
Tower mi = min.poll();
mi.value++;
list1.add(ma.index);
list2.add(mi.index);
max.offer(ma);
min.offer(mi);
}
int s=max.peek().value-min.peek().value;
System.out.println(s+" "+m);
for(int i=0;i<m;i++){
System.out.println(list1.get(i)+" "+list2.get(i));
}
}
}
class Tower{
int index;
int value;
Tower(int index, int value){
this.index = index;
this.value = value;
}
}
塔
最新推荐文章于 2024-05-02 11:36:25 发布