Aunty Khong is preparing boxes of candies for students from a nearby school. The boxes are numbered from
to
and are initially empty. Box
has a capacity of
candies.
Aunty Khong spends days preparing the boxes. On day
, she performs an action specified by three integers
,
and
where
and
. For each box
satisfying
:
- If
, Aunty Khong adds candies to box
, one by one, until she has added exactly
candies or the box becomes full. In other words, if the box had
candies before the action, it will have
candies after the action.
- If
, Aunty Khong removes candies from box
, one by one, until she has removed exactly
candies or the box becomes empty. In other words, if the box had
candies before the action, it will have
candies after the action.
Your task is to determine the number of candies in each box after the days.
Implementation Details
You should implement the following procedure:
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v)
: an array of length
. For
,
denotes the capacity of box
.
,
and
: three arrays of length
. On day
, for
, Aunty Khong performs an action specified by integers
,
and
, as described above.
- This procedure should return an array of length
. Denote the array by
. For
,
should be the number of candies in box
after the
days.
Examples
Example 1
Consider the following call:
distribute_candies({10, 15, 13}, {0, 0}, {2, 1}, {20, -11})
This means that box has a capacity of
candies, box
has a capacity of
candies, and box
has a capacity of
candies.
At the end of day , box
has
candies, box
has
candies and box
has
candies.
At the end of day , box
has
candies, box
has
candies. Since
, there is no change in the number of candies in box
. The number of candies at the end of each day are summarized below:
Day | Box |
Box |
Box |
---|---|---|---|
As such, the procedure should return .
Constraints
for all
for all
for all
Subtasks
- (
points)
- (
points)
for all
- (
points)
- (
points)
and
for all
- (
points) No additional constraints.
Sample Grader
The sample grader reads in the input in the following format:
- line
:
- line
:
- line
:
- line
:
The sample grader prints your answers in the following format:
- line
:
Attachment Package
The sample grader and sample test cases are available here: candies.zip.
Comments