100 atcoder#ABC214C. [ABC214C] Distribution
[ABC214C] Distribution
Score : points
Problem Statement
There are creatures standing in a circle, called Snuke in counter-clockwise order.
When Snuke receives a gem at time , units of time later, it will hand that gem to Snuke at time . Here, Snuke is Snuke .
Additionally, Takahashi will hand a gem to Snuke at time .
For each , find the time when Snuke receives a gem for the first time. Assume that it takes a negligible time to hand a gem.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the time when Snuke receives a gem for the first time.
3
4 1 5
3 10 100
3
7
8
We will list the three Snuke's and Takahashi's actions up to time in chronological order.
Time : Takahashi hands a gem to Snuke .
Time : Snuke hands a gem to Snuke .
Time : Snuke hands a gem to Snuke .
Time : Takahashi hands a gem to Snuke .
Time : Snuke hands a gem to Snuke .
Time : Snuke hands a gem to Snuke .
After that, they will continue handing gems, though it will be irrelevant to the answer.
4
100 100 100 100
1 1 1 1
1
1
1
1
Note that the values and may not be distinct.
4
1 2 3 4
1 2 4 7
1
2
4
7
Note that a Snuke may perform multiple transactions simultaneously. Particularly, a Snuke may receive gems simultaneously from Takahashi and another Snuke.
8
84 87 78 16 94 36 87 93
50 22 63 28 91 60 64 27
50
22
63
28
44
60
64
27