Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2011
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. void solve() throws IOException {
  2.     int n = readInt();
  3.     int[] a = new int[n];
  4.     int s = 0;
  5.     for (int i = 0; i < n; i++) {
  6.         a[i] = readInt();
  7.         s += a[i];
  8.     }
  9.     if (s % n != 0) {
  10.         out.println("Unrecoverable configuration.");
  11.         return;
  12.     }
  13.     int mid = s / n;
  14.     int dif = 0;
  15.     for (int i = 0; i < n; i++) {
  16.         if (a[i] != mid) dif++;
  17.     }
  18.     if (dif == 0) {
  19.         out.println("Exemplary pages.");
  20.         return;
  21.     }
  22.     if (dif != 2) {
  23.         out.println("Unrecoverable configuration.");
  24.         return;
  25.     }
  26.     int from = -1, to = -1, vol = -1;
  27.     for (int i = 0; i < n; i++) {
  28.         if (a[i] != mid) {
  29.             if (a[i] < mid) {
  30.                 from = i+1;
  31.                 vol = mid - a[i];
  32.             } else {
  33.                 to = i+1;
  34.             }
  35.         }
  36.     }
  37.     out.printf("%d ml. from cup #%d to cup #%d.\n", vol, from, to);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement