codeforces-scrape

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

1616C.md (1628B)


      1 Source: https://codeforces.com/problemset/problem/1616/C
      2 
      3 C. Representative Edges
      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 An array $a_1, a_2, \ldots, a_n$ is good if and only if for every subsegment $1 \leq l \leq r \leq n$, the following holds: $a_l + a_{l + 1} + \ldots + a_r = \frac{1}{2}(a_l + a_r) \cdot (r - l + 1)$.
     22 
     23 You are given an array of integers $a_1, a_2, \ldots, a_n$. In one operation, you can replace any one element of this array with any real number. Find the minimum number of operations you need to make this array good.
     24 
     25 Input
     26 
     27 The first line of input contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases.
     28 
     29 Each of the next $t$ lines contains the description of a test case.
     30 
     31 In the first line you are given one integer $n$ ($1 \leq n \leq 70$): the number of integers in the array.
     32 
     33 The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-100 \leq a_i \leq 100$): the initial array.
     34 
     35 Output
     36 
     37 For each test case, print one integer: the minimum number of elements that you need to replace to make the given array good.
     38 
     39 Example
     40 
     41 Input
     42 
     43 ```
     44 5
     45 4
     46 1 2 3 4
     47 4
     48 1 1 2 2
     49 2
     50 0 -1
     51 6
     52 3 -2 4 -1 -4 0
     53 1
     54 -100
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 0
     61 2
     62 0
     63 3
     64 0
     65 ```
     66 
     67 Note
     68 
     69 In the first test case, the array is good already.
     70 
     71 In the second test case, one of the possible good arrays is $[1, 1, \underline{1}, \underline{1}]$ (replaced elements are underlined).
     72 
     73 In the third test case, the array is good already.
     74 
     75 In the fourth test case, one of the possible good arrays is $[\underline{-2.5}, -2, \underline{-1.5}, -1, \underline{-0.5}, 0]$.