codeforces-scrape

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

1452B.md (2327B)


      1 Source: https://codeforces.com/problemset/problem/1452/B
      2 
      3 B. Toy Blocks
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 are asked to watch your nephew who likes to play with toy blocks in a strange way.
     22 
     23 He has $n$ boxes and the $i$-th box has $a_i$ blocks. His game consists of two steps:
     24 
     25 1. he chooses an arbitrary box $i$;
     26 2. he tries to move all blocks from the $i$-th box to other boxes.
     27 
     28 If he can make the same number of blocks in each of $n - 1$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.
     29 
     30 You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $i$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put?
     31 
     32 Input
     33 
     34 The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
     35 
     36 The first line of each test case contains the integer $n$ ($2 \le n \le 10^5$) — the number of boxes.
     37 
     38 The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$) — the number of blocks in each box.
     39 
     40 It's guaranteed that the sum of $n$ over test cases doesn't exceed $10^5$.
     41 
     42 Output
     43 
     44 For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite.
     45 
     46 Example
     47 
     48 Input
     49 
     50 ```
     51 3
     52 3
     53 3 2 2
     54 4
     55 2 2 3 2
     56 3
     57 0 3 0
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 1
     64 0
     65 3
     66 ```
     67 
     68 Note
     69 
     70 In the first test case, you can, for example, put one extra block into the first box and make $a = [4, 2, 2]$. If your nephew chooses the box with $4$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $2$ blocks then he will move these two blocks to the other box with $2$ blocks.
     71 
     72 In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.
     73 
     74 In the third test case, you should put $3$ extra blocks. For example, you can put $2$ blocks in the first box and $1$ block in the third box. You'll get array $a = [2, 3, 1]$.