#K39227. Ball Passing Strategy

    ID: 26374 Type: Default 1000ms 256MiB

Ball Passing Strategy

Ball Passing Strategy

You are given five integers representing the positions of players P, Q, R, and S on a one-dimensional field and an integer k, the maximum distance a ball can be passed in one move.

A pass between two players is valid if the distance between their positions satisfies the inequality: $$|a-b| \leq k.$$

The ball can be passed directly from P to S, or indirectly via the intermediate players Q and/or R. In particular, the following routes are allowed:

  • Direct pass: P \(\to\) S
  • Two-hop passes: P \(\to\) Q \(\to\) S or P \(\to\) R \(\to\) S
  • Three-hop passes: P \(\to\) Q \(\to\) R \(\to\) S or P \(\to\) R \(\to\) Q \(\to\) S

Output Yes if there exists a valid passing route from P to S that respects the distance limit at each pass, otherwise output No.

inputFormat

The input is read from stdin and consists of a single line containing five space-separated integers: p, q, r, s, and k.

Here:

  • p is the position of player P.
  • q is the position of player Q.
  • r is the position of player R.
  • s is the position of player S.
  • k is the maximum distance that can be passed in one move.

outputFormat

Output a single line to stdout containing either Yes if a valid passing sequence exists or No otherwise.

## sample
2 5 8 3 4
Yes