102142: [AtCoder]ABC214 C - Distribution

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

There are $N$ creatures standing in a circle, called Snuke $1, 2, ..., N$ in counter-clockwise order.

When Snuke $i$ $(1 \leq i \leq N)$ receives a gem at time $t$, $S_i$ units of time later, it will hand that gem to Snuke $i+1$ at time $t+S_i$. Here, Snuke $N+1$ is Snuke $1$.

Additionally, Takahashi will hand a gem to Snuke $i$ at time $T_i$.

For each $i$ $(1 \leq i \leq N)$, find the time when Snuke $i$ receives a gem for the first time. Assume that it takes a negligible time to hand a gem.

Constraints

  • $1 \leq N \leq 200000$
  • $1 \leq S_i,T_i \leq 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$S_1$ $S_2$ $\ldots$ $S_N$
$T_1$ $T_2$ $\ldots$ $T_N$

Output

Print $N$ lines. The $i$-th line $(1 \leq i \leq N)$ should contain the time when Snuke $i$ receives a gem for the first time.


Sample Input 1

3
4 1 5
3 10 100

Sample Output 1

3
7
8

We will list the three Snuke's and Takahashi's actions up to time $13$ in chronological order.

Time $3$: Takahashi hands a gem to Snuke $1$.

Time $7$: Snuke $1$ hands a gem to Snuke $2$.

Time $8$: Snuke $2$ hands a gem to Snuke $3$.

Time $10$: Takahashi hands a gem to Snuke $2$.

Time $11$: Snuke $2$ hands a gem to Snuke $3$.

Time $13$: Snuke $3$ hands a gem to Snuke $1$.

After that, they will continue handing gems, though it will be irrelevant to the answer.


Sample Input 2

4
100 100 100 100
1 1 1 1

Sample Output 2

1
1
1
1

Note that the values $S_i$ and $T_i$ may not be distinct.


Sample Input 3

4
1 2 3 4
1 2 4 7

Sample Output 3

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.


Sample Input 4

8
84 87 78 16 94 36 87 93
50 22 63 28 91 60 64 27

Sample Output 4

50
22
63
28
44
60
64
27

Input

题意翻译

## 题目描述 $N$ 人排列在圆周上,逆时针方向编号为 $1,2....N$ 。 第 $i(1≤i≤N)$ 个人在时刻 $t$ 拿到宝石后,在 $S_i$ 个单位时间后,即在时刻 $t+S_i$ 将该宝石交给第 $i+1$ 个人。特别的,第 $N$ 个人给向第 $1$ 个人。 另外,高桥在时间 $T_i$ 将宝石交给第 $i$ 个人。 对于所有 $i(1≤i≤N)$,请求出 i 号人第一次得到宝石的时刻。另外,宝石交接所需的时间可以忽略。 ### 输入格式 第一行 $N$ 第二行 $S_1,S_2,……S_N$ 第三行 $T_1,T_2,……T_N$ ### 输出格式 输出 $N$ 行。在 $i(1≤i≤N)$ 行中,输出第 $i$ 个人第一次得到宝石的时刻。 ### 说明/提示 $1≤N≤200000$ $1≤Si,Ti≤10^9$ 输入全部为整数。

Output

分数:300分 部分 问题说明 有N只名为Snuke 1、2、...、N的生物按逆时针方向站立。 当Snuke i(1≤i≤N)在时间t收到一颗宝石时,经过S_i单位时间后,它将在时间t+S_i将那颗宝石交给Snuke i+1。这里,Snuke N+1是Snuke 1。 此外,Takahashi将在时间T_i将一颗宝石交给Snuke i。 对于每个i(1≤i≤N),找出Snuke i首次收到宝石的时间。假设传递宝石所需的时间可以忽略不计。 部分 约束 * 1≤N≤200000 * 1≤S_i,T_i≤10^9 * 输入中的所有值都是整数。 部分 输入 输入格式如下: N S_1 S_2 ... S_N T_1 T_2 ... T_N 部分 输出 打印N行。第i行(1≤i≤N)应包含Snuke i首次收到宝石的时间。 部分 样例输入1 3 4 1 5 3 10 100 部分 样例输出1 3 7 8 我们将按时间顺序列出时间13之前三个Snuke和Takahashi的行为。 时间3:Takahashi将一颗宝石交给Snuke 1。 时间7:Snuke 1将一颗宝石交给Snuke 2。 时间8:Snuke 2将一颗宝石交给Snuke 3。 时间10:Takahashi将一颗宝石交给Snuke 2。 时间11:Snuke 2将一颗宝石交给Snuke 3。 时间13:Snuke 3将一颗宝石交给Snuke 1。 之后,他们将继续传递宝石,但与答案无关。 部分 样例输入2 4 100 100 100 100 1 1 1 1 部分 样例输出2 1 1 1 1 请注意,S_i和T_i的值可能不唯一。 部分 样例输入3 4 1 2 3 4 1 2 4 7 部分 样例输出3 1 2 4 7 请注意,一个Snuke可以同时执行多次交易。特别是,一个Snuke可以从Takahashi和其他Snuke同时收到宝石。 部分 样例输入4 8 84 87 78 16 94 36 87 93 50 22 63 28 91 60 64 27 部分 样例输出4 50 22 63 28 44 60 64 27

加入题单

算法标签: