#P9728. [EC Final 2022] Dining Professors

[EC Final 2022] Dining Professors

题目描述

Prof. Pang invited nn professors to his banquet. The professors sit at a round table. For all ii from 11 to nn, professor ii sits adjacent to professor (imodn)+1(i \bmod n) + 1 and ((i+n2)modn)+1((i + n - 2)\bmod n) + 1.

Prof. Pang prepared nn dishes. There are nn positions on the table. Position ii is in front of professor ii. Professor ii can access only the dishes placed at positions ii, (imodn)+1(i \bmod n) + 1, and ((i+n2)modn)+1((i + n - 2)\bmod n) + 1. Prof. Pang will place exactly one dish at each position.

Among the dishes, aa of them are spicy and nan-a of them are not spicy. Some (possibly 00) professors are unable to have spicy food. If a professor can have spicy food, his/her satisfaction level is the number of dishes (no matter spicy or not) he/she can access. If a professor cannot have spicy food, his/her satisfaction level is the number of not spicy dishes he/she can access.

Prof. Pang knows whether each professor can have spicy food or not. Please help him to arrange the dishes on the table so that the sum of satisfaction levels over all the professors is maximized. Output the maximum sum.

输入格式

The first line contains two integers n,an, a (3n105,0an3\le n\le 10^5, 0\le a\le n).

The second line contains nn integers b1,,bnb_1, \ldots, b_n. bib_i is 00 or 11. bi=1b_i=1 means professor ii can have spicy food. bi=0b_i=0 means professor ii cannot have spicy food.

输出格式

Output one integer representing the answer in one line.

题目大意

【题目描述】

庞教授邀请了 nn 位教授参加他的宴会。教授们坐在一个圆桌周围。对于所有 ii,从 11nn,教授 ii 坐在教授 (imodn)+1(i \bmod n) + 1((i+n2)modn)+1((i + n - 2)\bmod n) + 1 旁边。

庞教授准备了 nn 道菜。桌子上有 nn 个位置。位置 ii 在教授 ii 的前面。教授 ii 只能接触到放在位置 ii(imodn)+1(i \bmod n) + 1((i+n2)modn)+1((i + n - 2)\bmod n) + 1 处的菜。庞教授将在每个位置上放置一道菜。

在这些菜中,有 aa 道是辣的,nan-a 道是不辣的。有些(可能为 00)教授不能吃辣的食物。如果一位教授可以吃辣的食物,他/她的满意度水平是他/她可以接触到的菜的数量(无论是辣的还是不辣的)。如果一位教授不能吃辣的食物,他/她的满意度水平是他/她可以接触到的不辣的菜的数量。

庞教授知道每位教授是否可以吃辣的食物。请帮助他安排桌子上的菜,使得所有教授的满意度水平之和最大化。输出最大的总和。

【输入格式】

第一行包含两个整数 n,an, a (3n105,0an3\le n\le 10^5, 0\le a\le n)。

第二行包含 nn 个整数 b1,,bnb_1, \ldots, b_nbib_i0011bi=1b_i=1 表示教授 ii 可以吃辣的食物。bi=0b_i=0 表示教授 ii 不能吃辣的食物。

【输出格式】

输出一行一个整数,表示答案。

翻译来自于:ChatGPT

5 2
1 0 1 0 1

13