codeforces-scrape

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

920A.md (3349B)


      1 Source: https://codeforces.com/problemset/problem/920/A
      2 
      3 A. Water The Garden
      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 It is winter now, and Max decided it's about time he watered the garden.
     22 
     23 The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *x**i* is turned on, then after one second has passed, the bed *x**i* will be watered; after two seconds have passed, the beds from the segment [*x**i* - 1, *x**i* + 1] will be watered (if they exist); after *j* seconds have passed (*j* is an integer number), the beds from the segment [*x**i* - (*j* - 1), *x**i* + (*j* - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [*x**i* - 2.5, *x**i* + 2.5] will be watered after 2.5 seconds have passed; only the segment [*x**i* - 2, *x**i* + 2] will be watered at that moment.
     24 
     25  ![](https://espresso.codeforces.com/b708fecdfb8d8ab53a19865ec9979981caf68a46.png) The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.  ![](https://espresso.codeforces.com/ed40706bef97707f5a0b1d41b49f2a34f16de9c3.png) The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed. 
     26 
     27 Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
     28 
     29 Input
     30 
     31 The first line contains one integer *t* — the number of test cases to solve (1 ≤ *t* ≤ 200).
     32 
     33 Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1 ≤ *n* ≤ 200, 1 ≤ *k* ≤ *n*) — the number of garden beds and water taps, respectively.
     34 
     35 Next line contains *k* integers *x**i* (1 ≤ *x**i* ≤ *n*) — the location of *i*-th water tap. It is guaranteed that for each ![](https://espresso.codeforces.com/fe03c352479a1f92e4a3d577006ed0f1fff0ee43.png) condition *x**i* - 1 < *x**i* holds.
     36 
     37 It is guaranteed that the sum of *n* over all test cases doesn't exceed 200.
     38 
     39 Note that in hacks you have to set *t* = 1.
     40 
     41 Output
     42 
     43 For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 3  
     51 5 1  
     52 3  
     53 3 3  
     54 1 2 3  
     55 4 1  
     56 1
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 3  
     63 1  
     64 4
     65 ```
     66 
     67 Note
     68 
     69 The first example consists of 3 tests:
     70 
     71 1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
     72 2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
     73 3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.