#P9429. [NAPC-#1] Stage1 - Simple

[NAPC-#1] Stage1 - Simple

Background

Problem Description

Brief Statement

Given n,m,k,Sn, m, k, S, construct an integer sequence aa of length nn such that:

  • 0aim,i[1,n]0 \leqslant a_i \leqslant m, \forall i \in [1, n] (each element of aa is at least 00 and at most mm).
  • aiai1k,i(1,n]|a_i - a_{i-1}| \leqslant k, \forall i \in (1, n] (for every two adjacent elements in aa, the absolute difference is at most kk).
  • (i=1nai)=S(\sum_{i=1}^n a_i) = S (the sum of all elements in aa is SS).

A solution is guaranteed to exist.

Original Statement

I forgot what happened before, but you followed kid and traveled to ic (I wanna be the Creator) and arrived in front of a level editor. The map has width nn and height (m+1)(m+1), and you cannot change these. There are also SS unplaced 1×11 \times 1 bricks. Now you need to help kid place them, meaning: place these SS bricks so that kid can pass. The requirements are:

  1. Bricks have gravity, so a brick can only be placed on the bottom boundary or on top of another brick. You cannot place multiple bricks at the same (x,y)(x, y) coordinate.
  2. You must leave at least one gap for kid to pass, so in each column you can place at most mm bricks (since the map height is m+1m+1). Note that in ic levels, the bottom boundary does not cause damage, so a column may also have no bricks.
  3. kid’s jumping ability and the ability to fall from a height without getting hurt are limited, described by a non-negative integer kk: the absolute difference between the numbers of bricks placed in adjacent columns cannot exceed kk, otherwise the level is impossible for kid. ((But note: this rule does not restrict the height of the first column, since kid’s spawn point is in the first column.))
  4. You must place all SS bricks, no more and no less.

Creator will not make things difficult for you, so there is always a level that satisfies all the rules above.

For easier output, you only need to give how many bricks are in the ii-th column (denote it as aia_i), i.e., output the sequence aa. It is easy to prove that a valid sequence aa corresponds one-to-one with a valid level.

Input Format

A single line with 44 non-negative integers n,m,k,Sn, m, k, S.

Output Format

Output one line with nn non-negative integers representing your constructed sequence aa. If there are multiple possible sequences, output any one that satisfies the requirements. It is guaranteed that at least one sequence satisfies the requirements.

4 6 2 11
2 4 2 3
3 4 5 6
4 2 0

Hint

Constraints

This problem has 1010 test points, equally weighted.

  • For 20%20\% of the testdata, S=nmS = n \cdot m.
  • For 20%20\% of the testdata, k=0k = 0.
  • For 20%20\% of the testdata, k=109k = 10^9.

For 100%100\% of the testdata, 1n,m1051 \leqslant n, m \leqslant 10^5, 0k1090 \leqslant k \leqslant 10^9, 0Snm0 \leqslant S \leqslant n \cdot m.

Hint

In ancient times there was a number, its name was SS. SS can be so large that one int may (possibly) not hold it.

Sample Explanation #1

The level corresponding to the sample output is as follows.

Note that there may be multiple valid levels that meet the conditions.

Translated by ChatGPT 5