Universal Cup Judging System

Universal Cup

Time Limit: 1 s Memory Limit: 256 MB Total points: 100 Difficulty: [show]
Statistics

Prof. Pang は $n$ 人の教授を宴会に招待した。教授たちは円卓に座っている。すべての $i$ ($1 \le i \le n$) について、教授 $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 は各場所にちょうど 1 つずつ料理を配置する。

料理のうち、$a$ 個は辛い料理であり、$n - a$ 個は辛くない料理である。一部の教授(0 人の場合もある)は辛い料理を食べることができない。もし教授が辛い料理を食べられる場合、その教授の満足度はアクセス可能な料理の数(辛いかどうかは問わない)となる。もし教授が辛い料理を食べられない場合、その教授の満足度はアクセス可能な辛くない料理の数となる。

Prof. Pang は各教授が辛い料理を食べられるかどうかを知っている。すべての教授の満足度の合計が最大となるようにテーブル上の料理を配置するのを手伝ってほしい。最大となる合計値を出力せよ。

入力

1 行目に 2 つの整数 $n, a$ ($3 \le n \le 10^5, 0 \le a \le n$) が与えられる。

2 行目に $n$ 個の整数 $b_1, \dots, b_n$ が与えられる。$b_i$ は 0 または 1 である。$b_i = 1$ は教授 $i$ が辛い料理を食べられることを意味し、$b_i = 0$ は教授 $i$ が辛い料理を食べられないことを意味する。

出力

答えとなる整数を 1 行で出力せよ。

入出力例

入力 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.