CF1100A.Roman and Browser
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
He decided to accomplish this by closing every k-th (2≤k≤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⋅k that satisfy the following condition: 1≤c≤n and i is an integer (it may be positive, negative or zero).
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.
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.
今天早上,罗马醒来后打开了浏览器,其中有 n 个已打开的标签页,编号从 1 到 n。这些标签页分为两类:一类包含考试所需的信息,另一类是社交网站。罗马觉得打开的标签页太多了,因此决定关闭其中一部分。
他决定通过关闭所有第 k 个标签页(2≤k≤n−1)来实现这一目标。只有完成这一步后,他才会决定是复习考试还是浏览社交网络。形式化地说,罗马将先选定一个标签页(设其编号为 b),然后关闭所有满足以下条件的标签页(编号为 c=b+i⋅k):1≤c≤n,其中 i 为任意整数(可正、可负或为零)。
例如,若 k=3,n=14,且罗马选择 b=8,则他将关闭编号为 2、5、8、11 和 14 的标签页。
关闭标签页后,罗马将计算剩余的考试信息类标签页数量(记为 e)与剩余的社交网站类标签页数量(记为 s)。请帮助罗马计算 ∣e−s∣ 的最大可能绝对值,以便他能更轻松地决定接下来该做什么。
输入格式
The first line contains two integers n and k (2≤k<n≤100) — the amount of tabs opened currently and the distance between the tabs closed.
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.
第一行包含两个整数 n 和 k(2≤k<n≤100)—— 分别表示当前打开的标签页数量,以及被关闭的标签页之间的距离。
第二行包含 n 个整数,每个整数为 1 或 −1。第 i 个整数表示第 i 个标签页的类型:若为 1,则该标签页包含测试所需的信息;若为 −1,则该标签页为社交网络标签页。
输出格式
Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types ∣e−s∣.
输出一个整数——不同类型剩余标签页数量之间的最大绝对差值 ∣e−s∣。
输入输出样例
输入#1
4 2 1 1 -1 1
输出#1
2
输入#2
14 3 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
输出#2
9
说明/提示
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.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
在第一个例子中,我们可以选择 b=1 或 b=3。随后我们将删除每种类型的一个标签页,剩余的标签页则全部包含测试信息。因此,e=2,s=0,且 ∣e−s∣=2。
在第二个例子中,相反地,我们只能保留打开社交网络的标签页。
输入解题思路,AI测评打分。不知道怎么写?