|
| 1 | +import java.io.*; |
| 2 | +import java.util.*; |
| 3 | + |
| 4 | +/** |
| 5 | + * Built using CHelper plug-in |
| 6 | + * Actual solution is at the top |
| 7 | + * |
| 8 | + * @author kronos |
| 9 | + */ |
| 10 | +public class Main { |
| 11 | + public static void main(String[] args) { |
| 12 | + InputStream inputStream = System.in; |
| 13 | + OutputStream outputStream = System.out; |
| 14 | + FastScanner in = new FastScanner(inputStream); |
| 15 | + PrintWriter out = new PrintWriter(outputStream); |
| 16 | + TaskC solver = new TaskC(); |
| 17 | + solver.solve(1, in, out); |
| 18 | + out.close(); |
| 19 | + } |
| 20 | + |
| 21 | + static class TaskC { |
| 22 | + public void solve(int testNumber, FastScanner in, PrintWriter out) { |
| 23 | + int n = in.nextInt(); |
| 24 | + int w = in.nextInt(); |
| 25 | + Friend[] f = new Friend[n]; |
| 26 | + int sum = 0, q; |
| 27 | + for (int i = 0; i < n; i++) { |
| 28 | + f[i] = new Friend(in.nextInt(), i); |
| 29 | + sum += f[i].ans; |
| 30 | + w -= f[i].ans; |
| 31 | + } |
| 32 | + |
| 33 | + if (w < 0) { |
| 34 | + out.println(-1); |
| 35 | + } else { |
| 36 | + Arrays.sort(f, new Comparator<Friend>() { |
| 37 | + |
| 38 | + public int compare(final Friend left, final Friend right) { |
| 39 | + return left.a - right.a; |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + for (int i = n - 1; (i >= 0) && (w > 0); i--) { |
| 44 | + q = Integer.min(f[i].left(), w); |
| 45 | + f[i].ans += q; |
| 46 | + w -= q; |
| 47 | + } |
| 48 | + |
| 49 | + Arrays.sort(f, new Comparator<Friend>() { |
| 50 | + |
| 51 | + public int compare(final Friend left, final Friend right) { |
| 52 | + return left.i - right.i; |
| 53 | + } |
| 54 | + }); |
| 55 | + |
| 56 | + for (int i = 0; i < n; i++) { |
| 57 | + out.printf("%d ", f[i].ans); |
| 58 | + } |
| 59 | + } |
| 60 | + out.flush(); |
| 61 | + } |
| 62 | + |
| 63 | + class Friend { |
| 64 | + public int a; |
| 65 | + public int ans; |
| 66 | + public int i; |
| 67 | + |
| 68 | + Friend(int a, int i) { |
| 69 | + this.a = a; |
| 70 | + this.ans = a / 2 + a % 2; |
| 71 | + this.i = i; |
| 72 | + } |
| 73 | + |
| 74 | + public int left() { |
| 75 | + return a - ans; |
| 76 | + } |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + } |
| 81 | + |
| 82 | + static class FastScanner { |
| 83 | + BufferedReader br; |
| 84 | + StringTokenizer st; |
| 85 | + |
| 86 | + public FastScanner() { |
| 87 | + br = new BufferedReader(new InputStreamReader(System.in)); |
| 88 | + } |
| 89 | + |
| 90 | + public FastScanner(InputStream stream) { |
| 91 | + br = new BufferedReader(new InputStreamReader(stream)); |
| 92 | + } |
| 93 | + |
| 94 | + public FastScanner(String s) { |
| 95 | + try { |
| 96 | + br = new BufferedReader(new FileReader(s)); |
| 97 | + } catch (FileNotFoundException e) { |
| 98 | + e.printStackTrace(); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + public String next() { |
| 103 | + while (st == null || !st.hasMoreTokens()) { |
| 104 | + try { |
| 105 | + st = new StringTokenizer(br.readLine()); |
| 106 | + } catch (IOException e) { |
| 107 | + } |
| 108 | + } |
| 109 | + return st.nextToken(); |
| 110 | + } |
| 111 | + |
| 112 | + public int nextInt() { |
| 113 | + return Integer.parseInt(next()); |
| 114 | + } |
| 115 | + |
| 116 | + } |
| 117 | +} |
0 commit comments