codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1715B.md (2169B)


      1 Source: https://codeforces.com/problemset/problem/1715/B
      2 
      3 B. Beautiful Array
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Stanley defines the beauty of an array $a$ of length $n$, which contains non-negative integers, as follows: $$\sum\limits_{i = 1}^{n} \left \lfloor \frac{a_{i}}{k} \right \rfloor,$$ which means that we divide each element by $k$, round it down, and sum up the resulting values.
     22 
     23 Stanley told Sam the integer $k$ and asked him to find an array $a$ of $n$ non-negative integers, such that the beauty is equal to $b$ and the sum of elements is equal to $s$. Help Sam — find any of the arrays satisfying the conditions above.
     24 
     25 Input
     26 
     27 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows.
     28 
     29 The first line of each test case contains integers $n$, $k$, $b$, $s$ ($1 \leq n \leq 10^{5}$, $1 \leq k \leq 10^{9}$, $0 \leq b \leq 10^{9}$, $0 \leq s \leq 10^{18}$).
     30 
     31 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
     32 
     33 Output
     34 
     35 For each test case print $-1$ if such array $a$ does not exist. Otherwise print $n$ non-negative integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_{i} \leq 10^{18}$) — the answer.
     36 
     37 Example
     38 
     39 Input
     40 
     41 ```
     42 8
     43 
     44 1 6 3 100
     45 
     46 3 6 3 12
     47 
     48 3 6 3 19
     49 
     50 5 4 7 38
     51 
     52 5 4 7 80
     53 
     54 99978 1000000000 100000000 1000000000000000000
     55 
     56 1 1 0 0
     57 
     58 4 1000000000 1000000000 1000000000000000000
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 -1
     65 -1
     66 0 0 19
     67 0 3 3 3 29
     68 -1
     69 -1
     70 0
     71 0 0 0 1000000000000000000
     72 ```
     73 
     74 Note
     75 
     76 In the first, the second, the fifth and the sixth test cases of the example it is possible to show that such array does not exist.
     77 
     78 In the third testcase of the example $a = [0, 0, 19]$. The sum of elements in it is equal to 19, the beauty of it is equal to $\left ( \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{19}{6} \right \rfloor \right ) = (0 + 0 + 3) = 3$.
     79 
     80 In the fourth testcase of the example $a = [0, 3, 3, 3, 29]$. The sum of elements in it is equal to $38$, the beauty of it is equal to $(0 + 0 + 0 + 0 + 7) = 7$.