1100A.md (2399B)
1 Source: https://codeforces.com/problemset/problem/1100/A 2 3 A. Roman and Browser 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 This morning, Roman woke up and opened the browser with $n$ opened tabs numbered from $1$ to $n$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them. 22 23 He decided to accomplish this by closing every $k$-th ($2 \leq k \leq n - 1$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $b$) and then close all tabs with numbers $c = b + i \cdot k$ that satisfy the following condition: $1 \leq c \leq n$ and $i$ is an integer (it may be positive, negative or zero). 24 25 For example, if $k = 3$, $n = 14$ and Roman chooses $b = 8$, then he will close tabs with numbers $2$, $5$, $8$, $11$ and $14$. 26 27 After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $e$) and the amount of remaining social network tabs ($s$). Help Roman to calculate the maximal absolute value of the difference of those values $|e - s|$ so that it would be easy to decide what to do next. 28 29 Input 30 31 The first line contains two integers $n$ and $k$ ($2 \leq k \lt n \leq 100$) — the amount of tabs opened currently and the distance between the tabs closed. 32 33 The second line consists of $n$ integers, each of them equal either to $1$ or to $-1$. The $i$-th integer denotes the type of the $i$-th tab: if it is equal to $1$, this tab contains information for the test, and if it is equal to $-1$, it's a social network tab. 34 35 Output 36 37 Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $|e - s|$. 38 39 Examples 40 41 Input 42 43 ``` 44 4 2 45 1 1 -1 1 46 ``` 47 48 Output 49 50 ``` 51 2 52 ``` 53 54 Input 55 56 ``` 57 14 3 58 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 59 ``` 60 61 Output 62 63 ``` 64 9 65 ``` 66 67 Note 68 69 In the first example we can choose $b = 1$ or $b = 3$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $e = 2$ and $s = 0$ and $|e - s| = 2$. 70 71 In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.