-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathJ.java
57 lines (48 loc) · 1.45 KB
/
J.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Scanner;
public class J {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(new File("bureaucracy.in"));
FileWriter fileWriter = new FileWriter(new File("bureaucracy.out"));
int n = scanner.nextInt();
long m = scanner.nextInt();
long obhod = m / n;
long sum = 0;
int count = n;
ArrayDeque<Long> ochered = new ArrayDeque<>();
for (int i = 0; i < n; i++) {
long cur = scanner.nextInt();
if (cur <= obhod) {
count--;
m = m - cur;
} else {
cur = cur - obhod;
m = m - obhod;
ochered.addLast(cur);
sum = sum + cur;
}
}
if (sum <= m) {
fileWriter.write(-1 + "");
} else {
while (m != 0) {
long cur = ochered.removeFirst();
m--;
cur--;
if (cur > 0) {
ochered.addLast(cur);
} else {
count--;
}
}
fileWriter.write(count + "\n");
while (!ochered.isEmpty()) {
fileWriter.write(ochered.removeFirst() + " ");
}
}
fileWriter.flush();
}
}