1088B.md (1474B)
1 Source: https://codeforces.com/problemset/problem/1088/B 2 3 B. Ehab and subtraction 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 You're given an array $a$. You should repeat the following operation $k$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. 22 23 Input 24 25 The first line contains integers $n$ and $k$ $(1 \le n,k \le 10^5)$, the length of the array and the number of operations you should perform. 26 27 The second line contains $n$ space-separated integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 10^9)$, the elements of the array. 28 29 Output 30 31 Print the minimum non-zero element before each operation in a new line. 32 33 Examples 34 35 Input 36 37 ``` 38 3 5 39 1 2 3 40 ``` 41 42 Output 43 44 ``` 45 1 46 1 47 1 48 0 49 0 50 ``` 51 52 Input 53 54 ``` 55 4 2 56 10 3 5 3 57 ``` 58 59 Output 60 61 ``` 62 3 63 2 64 ``` 65 66 Note 67 68 In the first sample: 69 70 In the first step: the array is $[1,2,3]$, so the minimum non-zero element is 1. 71 72 In the second step: the array is $[0,1,2]$, so the minimum non-zero element is 1. 73 74 In the third step: the array is $[0,0,1]$, so the minimum non-zero element is 1. 75 76 In the fourth and fifth step: the array is $[0,0,0]$, so we printed 0. 77 78 In the second sample: 79 80 In the first step: the array is $[10,3,5,3]$, so the minimum non-zero element is 3. 81 82 In the second step: the array is $[7,0,2,0]$, so the minimum non-zero element is 2.