2015-16 Woburn Challenge Finals - Senior Division
At last, the final battle for Scarberia is upon us! The cows and monkeys
have agreed that the fighting will take place on a circle of
pastures, connected to one another in a cycle by
two-way bridges. The
-th bridge can support a weight of at most
pounds, and connects pastures
and
, or pastures
and
.
The monkeys' base of operations is located in pasture , and they have
troops stationed in all of the other pastures. The monkeys, being
masterful makers of war, are keenly aware that the most effective
soldiers are well-fed soldiers. As such, they have a convoy of
trucks which will deliver bananas from their base
daily. The
-th truck has a weight of
pounds, and every day, it will depart from pasture
, driving
around amongst the pastures and delivering
bananas to each other pasture that it can reach. Each truck can
only cross bridges which can at least support its weight, and it can
drive back and forth as much as necessary (even revisiting pastures
multiple times), but it will only deliver a load of bananas to each
pasture at most once. Therefore, each day, the
-th truck will deliver
between
and
bananas in total.
The battle is scheduled to last for
days,
and in order to manage their banana hoard successfully, the monkeys
would like to determine how many bananas their trucks will deliver on
each day. However, this aspect of the war promises to be particularly
dynamic, as those dastardly cows are also well aware of the military
importance of the supply chain and will attempt to sabotage it, while
the monkeys will hopefully enact the necessary countermeasures. One
event will occur at the start of each day (before the trucks roll out
to make their deliveries, with the type of the event on the
-th day
indicated by
):
- If
, the cows will undermine the structural integrity of the
-th
bridge, permanently reducing its maximum supported weight by
pounds. It's guaranteed that it will still be able to support a weight of at least
pound.
- If
, the monkeys will remodel their
-th
truck such that it henceforth weighs
pounds. Note that this could cause its weight to increase (thanks to cows cleverly disguised as monkey mechanics).
The outcome of the entire war, and the monkeys' opportunity to reclaim
Scarberia once and for all, depends on this supply chain! Can you help
the monkeys determine how many bananas their trucks will deliver in
total on each of the days of the battle?
In test cases worth of the points,
,
, and
.
In test cases worth another of the points,
,
,
and
.
In test cases worth another of the points,
.
In test cases worth another of the points,
.
Input Specification
The first line of input consists of three space-separated integers, ,
, and
.
lines follow. The
-th of these lines consists of a single
integer,
(for
).
lines follow. The
-th of these lines consists of two
space-separated integers,
and
(for
).
lines follow. The
-th of these lines consists of three
space-separated integers,
,
, and
(for
).
Output Specification
Output lines. The
-th line of output should consist of a single
integer representing the total number of bananas delivered on the
-th
day (for
).
Note that each of these values may not fit within a 32-bit integer.
Sample Input
4 5 4
5
4
2
8
3 5
1 100
2 1
5 20
6 4
2 2 100
1 4 3
1 4 4
2 2 1
Sample Output
62
58
33
333
Explanation
On the first day, the first truck will deliver bananas each to
pastures
,
, and
. The second truck, now weighing
pounds, won't
deliver any bananas. The third truck will deliver
banana to each of
those
pastures, the fourth will deliver
bananas to pastures
and
, and the fifth will deliver
bananas to just pasture
. The total
number of bananas delivered on this day will then be
.
Comments