Problem:
﻿Score: 100 points

Problem Statement

In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively.

Two antennas can communicate directly if the distance between them is k or less, and they cannot if the distance is greater than k.

Determine if there exists a pair of antennas that cannot communicate directly.

Here, assume that the distance between two antennas at coordinates p and q (p < q) is q - p.

Constraints

a, b, c, d, e and k are integers between 0 and 123 (inclusive).

a < b < c < d < e

Input

Input is given from Standard Input in the following format:

a
b
c
d
e
k

Output

Print :( if there exists a pair of antennas that cannot communicate directly, and print Yay! if there is no such pair.

Sample Input 1

1
2
4
8
9
15

Sample Output 1

Yay!

In this case, there is no pair of antennas that cannot communicate directly, because:

the distance between A and B is 2 - 1 = 1

the distance between A and C is 4 - 1 = 3

the distance between A and D is 8 - 1 = 7

the distance between A and E is 9 - 1 = 8

the distance between B and C is 4 - 2 = 2

the distance between B and D is 8 - 2 = 6

the distance between B and E is 9 - 2 = 7

the distance between C and D is 8 - 4 = 4

the distance between C and E is 9 - 4 = 5

the distance between D and E is 9 - 8 = 1

and none of them is greater than 15. Thus, the correct output is Yay!.

Sample Input 2

15
18
26
35
36
18

Sample Output 2

:(

In this case, the distance between antennas A and D is 35 - 15 = 20 and exceeds 18, so they cannot communicate directly.
Thus, the correct output is :(.

Solution in Scala (2.11.7) (judge verdict: Runtime Error)

import scala.collection.mutable.PriorityQueue
import scala.collection.mutable.Set
import scala.util.Sorting

object Main {
  val pq = PriorityQueue[(Long, (Int, Int, Int))]()(scala.math.Ordering.by(v => v._1))
  val lines = scala.io.Source.stdin.getLines.toStream
  val Array(num_x, num_y, num_z, num_k) = lines(0).split(" ").map(_.toLong)
  val xs = lines(1).split(" ").map(_.toLong)
  val ys = lines(2).split(" ").map(_.toLong)
  val zs = lines(3).split(" ").map(_.toLong)
  Sorting.quickSort[Long](xs)(Ordering[Long].reverse)
  Sorting.quickSort[Long](ys)(Ordering[Long].reverse)
  Sorting.quickSort[Long](zs)(Ordering[Long].reverse)
  val checked = Set[(Int, Int, Int)]()
  pq.enqueue((xs(0) + ys(0) + zs(0)) -> (0, 0, 0))

  def main(args: Array[String]) = {
    bfs(num_k)
  }

  def bfs(max: Long = 3000, count: Long = 1): Unit = {
    val (value, (lx, ly, lz))  = pq.dequeue
    println(value)
    if (xs.length > lx+1 && !checked.contains((lx + 1, ly, lz))) {
      checked += ((lx+1, ly, lz))
      pq.enqueue((value - xs(lx) + xs(lx + 1)) -> (lx + 1, ly, lz))
    }
    if (ys.length > ly+1 && !checked.contains((lx, ly+1, lz))) {
      checked += ((lx, ly+1, lz))
      pq.enqueue((value - ys(ly) + ys(ly+1)) -> (lx, ly+1, lz))
    }
    if (zs.length > lz+1 && !checked.contains((lx, ly, lz+1))) {
      checked += ((lx, ly, lz+1))
      pq.enqueue((value - zs(lz) + zs(lz+1)) -> (lx, ly, lz+1))
    }
    if (count < max && (zs.length > lz+1 || ys.length > ly+1 || xs.length > lx+1)) {
      bfs(max, count + 1)
    }
  }
}