#P8518. [IOI 2021] 分糖果
[IOI 2021] 分糖果
Description
Aunt Khong is preparing boxes of candies for students at a nearby school. The boxes are numbered from to , and initially all boxes are empty. Box can hold at most candies (its capacity is ).
Aunt Khong spends days preparing the candy boxes. On day , she performs an operation based on three integers , , and , where and . For every box such that :
-
If , Aunt Khong puts candies into box one by one until she has put exactly candies or the box becomes full. That is, if the box contains candies before this operation, then after this operation it will contain candies.
-
If , Aunt Khong takes candies out of box one by one until she has taken out exactly candies or the box becomes empty. That is, if the box contains candies before this operation, then after this operation it will contain candies.
Your task is to compute the number of candies in each box after days.
Input Format
Implementation details
You need to implement the following function:
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 , is the capacity of box .
-
, , and : three arrays of length . On day , for , Aunt Khong performs the operation determined by integers , , and , as described in the statement.
Output Format
- The function should return an array of length . Let this array be . For , should be the number of candies in box after days.
3
10 15 13
2
0 2 20
0 1 -11
0 4 13
Hint
Example 1
Consider the following call:
distribute_candies([10, 15, 13], [0, 0], [2, 1], [20, -11])
This means box has capacity , box has capacity , and box has capacity .
At the end of day , box has candies, box has candies, and box has candies.
At the end of day , box has candies, and box has candies. Since , the number of candies in box does not change. The summary at the end of each day is as follows:
| Day | Box | Box | Box |
|---|---|---|---|
In this case, the function 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 the input in the following format:
- Line : .
- Line : .
- Line : .
- Line (): .
The sample grader prints your answer in the following format:
- Line : .
Translated by ChatGPT 5
京公网安备 11011102002149号