534C.md (2308B)
1 Source: https://codeforces.com/problemset/problem/534/C 2 3 C. Polycarpus' Dice 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 Polycarp has *n* dice *d*1, *d*2, ..., *d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1, *d*2, ..., *d**n*. However, she finds it enough to make a series of statements of the following type: dice *i* couldn't show number *r*. For example, if Polycarp had two six-faced dice and the total sum is *A* = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). 22 23 For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is *A*. 24 25 Input 26 27 The first line contains two integers *n*, *A* (1 ≤ *n* ≤ 2·105, *n* ≤ *A* ≤ *s*) — the number of dice and the sum of shown values where *s* = *d*1 + *d*2 + ... + *d**n*. 28 29 The second line contains *n* integers *d*1, *d*2, ..., *d**n* (1 ≤ *d**i* ≤ 106), where *d**i* is the maximum value that the *i*-th dice can show. 30 31 Output 32 33 Print *n* integers *b*1, *b*2, ..., *b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them. 34 35 Examples 36 37 Input 38 39 ``` 40 2 8 41 4 4 42 ``` 43 44 Output 45 46 ``` 47 3 3 48 ``` 49 50 Input 51 52 ``` 53 1 3 54 5 55 ``` 56 57 Output 58 59 ``` 60 4 61 ``` 62 63 Input 64 65 ``` 66 2 3 67 2 3 68 ``` 69 70 Output 71 72 ``` 73 0 1 74 ``` 75 76 Note 77 78 In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. 79 80 In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. 81 82 In the third sample from the statement *A* equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.