Universal Cup Judging System

Universal Cup

Límite de tiempo: 1 s Límite de memoria: 256 MB Puntuación total: 100 Dificultad: [mostrar]
Estadísticas

Prof. Pang 邀請了 $n$ 位教授參加他的宴會。教授們圍坐在一張圓桌旁。對於所有從 $1$ 到 $n$ 的 $i$,教授 $i$ 相鄰的教授分別是 $(i \pmod n) + 1$ 和 $((i + n - 2) \pmod n) + 1$。

Prof. Pang 準備了 $n$ 道菜。桌上有 $n$ 個位置,位置 $i$ 位於教授 $i$ 的正前方。教授 $i$ 只能取用放置在位置 $i$、$(i \pmod n) + 1$ 以及 $((i + n - 2) \pmod n) + 1$ 的菜餚。Prof. Pang 會在每個位置各放置一道菜。

在這些菜餚中,有 $a$ 道是辣的,而 $n - a$ 道是不辣的。有些教授(可能為 $0$ 位)無法吃辣。如果一位教授可以吃辣,他/她的滿意度為他/她能取到的菜餚總數(無論是否為辣的)。如果一位教授不能吃辣,他/她的滿意度為他/她能取到的不辣菜餚數量。

Prof. Pang 知道每位教授是否能吃辣。請協助他安排桌上的菜餚,使得所有教授的滿意度總和最大化。輸出該最大總和。

輸入格式

第一行包含兩個整數 $n, a$ ($3 \le n \le 10^5, 0 \le a \le n$)。

第二行包含 $n$ 個整數 $b_1, \dots, b_n$。$b_i$ 為 $0$ 或 $1$。$b_i = 1$ 表示教授 $i$ 可以吃辣,$b_i = 0$ 表示教授 $i$ 不能吃辣。

輸出格式

輸出一個整數,代表答案。

範例

輸入格式 1

5 2
1 0 1 0 1

輸出格式 1

13

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.