CF1100A.Roman and Browser

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This morning, Roman woke up and opened the browser with nn opened tabs numbered from 11 to nn. 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 kk-th (2≤k≤n−12 \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 bb) and then close all tabs with numbers c=b+i⋅kc = b + i \cdot k that satisfy the following condition: 1≤c≤n1 \leq c \leq n and ii is an integer (it may be positive, negative or zero).

For example, if k=3k = 3, n=14n = 14 and Roman chooses b=8b = 8, then he will close tabs with numbers 22, 55, 88, 1111 and 1414.

After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it ee) and the amount of remaining social network tabs (ss). Help Roman to calculate the maximal absolute value of the difference of those values ∣e−s∣|e - s| so that it would be easy to decide what to do next.

今天早上,罗马醒来后打开了浏览器,其中有 nn 个已打开的标签页,编号从 11 到 nn。这些标签页分为两类:一类包含考试所需的信息,另一类是社交网站。罗马觉得打开的标签页太多了,因此决定关闭其中一部分。

他决定通过关闭所有第 kk 个标签页(2≤k≤n−12 \leq k \leq n - 1)来实现这一目标。只有完成这一步后,他才会决定是复习考试还是浏览社交网络。形式化地说,罗马将先选定一个标签页(设其编号为 bb),然后关闭所有满足以下条件的标签页(编号为 c=b+i⋅kc = b + i \cdot k):1≤c≤n1 \leq c \leq n,其中 ii 为任意整数(可正、可负或为零)。

例如,若 k=3k = 3,n=14n = 14,且罗马选择 b=8b = 8,则他将关闭编号为 22、55、88、1111 和 1414 的标签页。

关闭标签页后,罗马将计算剩余的考试信息类标签页数量(记为 ee)与剩余的社交网站类标签页数量(记为 ss)。请帮助罗马计算 ∣e−s∣|e - s| 的最大可能绝对值,以便他能更轻松地决定接下来该做什么。

输入格式

The first line contains two integers nn and kk (2≤k<n≤1002 \leq k \lt n \leq 100) — the amount of tabs opened currently and the distance between the tabs closed.

The second line consists of nn integers, each of them equal either to 11 or to −1-1. The ii-th integer denotes the type of the ii-th tab: if it is equal to 11, this tab contains information for the test, and if it is equal to −1-1, it's a social network tab.

第一行包含两个整数 nn 和 kk(2≤k<n≤1002 \leq k \lt n \leq 100)—— 分别表示当前打开的标签页数量,以及被关闭的标签页之间的距离。

第二行包含 nn 个整数,每个整数为 11 或 −1-1。第 ii 个整数表示第 ii 个标签页的类型:若为 11,则该标签页包含测试所需的信息;若为 −1-1,则该标签页为社交网络标签页。

输出格式

Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types ∣e−s∣|e - s|.

输出一个整数——不同类型剩余标签页数量之间的最大绝对差值 ∣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=1b = 1 or b=3b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e=2e = 2 and s=0s = 0 and ∣e−s∣=2|e - s| = 2.

In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.

在第一个例子中,我们可以选择 b=1b = 1 或 b=3b = 3。随后我们将删除每种类型的一个标签页,剩余的标签页则全部包含测试信息。因此,e=2e = 2,s=0s = 0,且 ∣e−s∣=2|e - s| = 2。

在第二个例子中,相反地,我们只能保留打开社交网络的标签页。

输入解题思路,AI测评打分。不知道怎么写?

首页