A12317 | Roman and Browser
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 \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).
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.
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).
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.
输入格式
The first line contains two integers $n$ and $k$ ( $2 \leq k < n \leq 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.
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.
输出格式
Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $|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.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted