#FT0000018. Mancala 2 – Phân phối bóng theo vòng tròn (Mancala 2)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mancala 2 – Phân phối bóng theo vòng tròn (Mancala 2)
Mancala 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are boxes arranged in a circle and numbered through . Initially, box contains balls. Takahashi performs redistribution operations using box indices .
In operation , he takes every ball out of box , leaving that box empty. He then places one ball into each successive box in increasing cyclic order: first , then , and so on until he has no balls left. After box , he wraps around to box , so a box can receive multiple balls during one operation.
Each operation uses the box counts resulting from preceding operations. After all operations, output the numbers of balls in boxes through in index order. No intermediate answers are requested.
Input
- Line 1:
n mgives number of boxes and redistribution operations. - Line 2:
A_0 A_1 ... A_(n-1)gives the initial values in index order. - Line 3:
B_1 B_2 ... B_mlists the indices of the boxes chosen in the successive operations; each index is zero-based.
Output
Print exactly space-separated integers on one line. The -st number is the number of balls in box after operations.
Subtasks
Subtask 1 (20 points):
- .
- .
- for all .
- for all .
Subtask 2 (30 points):
- .
- .
- for all .
- for all .
Subtask 3 (50 points):
- .
- .
- for all .
- for all .
Examples
Input
5 3
1 2 3 4 5
2 4 0
Output
0 4 2 7 2
Explanation
Initially the five boxes contain [1, 2, 3, 4, 5] balls. The three chosen box indices are 2, 4, and 0.
-
Operation 1, box 2: take its balls and set its count to . Give one ball to boxes
3,4, and0in that order, wrapping around after index 4. The counts become[2, 2, 0, 5, 6]. -
Operation 2, box 4: take its balls and distribute them to boxes
0, 1, 2, 3, 4, 0. Box 0 receives two balls, and every other box receives one. The new counts are[4, 3, 1, 6, 1]. -
Operation 3, box 0: take its balls, then place one each in boxes
1, 2, 3, 4. The final counts are[0, 4, 2, 7, 2].
The answer is printed in box-index order on a single line: 0 4 2 7 2. The total of balls is conserved.