PEG Test – Oct 3rd, 2014
Due to the harmonic convergence, spirits are leaking out from the spirit world. Some spirits are represented by Raava, the spirit of peace and light, so they are kind and friendly; other dark spirits are corrupted by Vaatu, the spirit of chaos and darkness, and are in turn devious and destructive.
Avatar Korra and her uncle Unalaq are having a duel in the spirit world,
where light and dark spirits are entering the spirit world through the
spirit portals at the north and south poles. The spirit world can be
represented as a number line segment of length , that is, there are
positions on the number line labeled from
to
. At position
, is the spirit portal leading out to the north
pole physical world, and at position
is the spirit portal leading
out to the south pole of the physical world. Korra stands at position
and Unalaq stands at position
, deploying their spirits.
Korra sends out one light spirit every seconds towards Unalaq, and
Unalaq sends out one dark spirit every
seconds towards Korra
. Korra has
light spirits lined
up, numbered from
to
. Unalaq has
spirits lined up, numbered from
to
. Light spirit
has a
strength of
and dark spirit
has a strength of
. All
spirits move at a rate of
unit per second towards the opponent. If a
light spirit ever encounters a dark spirit (i.e. during the same second
they occupy the same position, or they switch positions), then the
stronger spirit will immediately consume the weaker spirit. If they are
both equally as strong, then the dark spirit will prevail due to the
impartiality of the convergence.
At the start, Korra and Unalaq will simultaneously deploy their first
spirit (light spirit and dark spirit
, respectively) at the opposite
portals. Light and dark spirits spawning will instantly appear at
positions
and
, respectively. When a light spirit reaches position
, they will instantly exit the spirit world (unless of course, a
dark spirit of greater or equal strength happens to spawn at
during
that exact moment, in which case the light spirit will be consumed and
not be able to exit the portal), and vice versa. Help Korra count how
many light and dark spirits will reach and exit through the opposite
portals after all of their spirits have been depleted.
Input Specification
Line 1: The integers ,
,
,
, and
.
Line 2: integers,
, representing the
strengths of the light spirits.
Line 3: integers,
, representing the
strengths of the dark spirits.
Output Specification
Two space-separated integers. The first represents the number of light
spirits that reach Unalaq's portal (position ) and can exit. The
second represents the number of dark spirits that reach Korra's portal
(position
) and can exit.
Sample Input
10 5 5 3 4
50 91 24
49 90 72 47
Sample Output
1 1
Comments