#P11068. 「QMSOI R1」 转转楼梯

「QMSOI R1」 转转楼梯

Background

The problem statement itself is the best background ().

Problem Description

Students do exercises every day, and they will pass through the spinning stairs.

The spinning stairs has n+1n+1 steps. For step i (1in+1)i \ (1\le i\le n+1), it has a spinning value aia_i, where ai{0,1}a_i\in\{0,1\}. In particular, an+1=0a_{n+1}=0.

For a step ii, if the spinning value of the next step is the same as it (that is, ai+1=aia_{i+1}=a_i), then we can walk down directly, costing 11 second. Otherwise, we need to spend 11 second to spin once to change the spinning value of the current step to 1ai1-a_i, and then spend another 11 second to walk down.

We need to do exercises for kk days. Every day, we walk from step 11 to step n+1n+1.

Please compute the total time for these kk days that students spend on the spinning stairs.

Input Format

The input has 22 lines.

The first line contains two numbers nn and kk.

The second line contains nn integers. The i (1in)i \ (1\leq i\leq n)-th number represents aia_i.

Output Format

Output one integer in one line, representing the total time spent on the spinning stairs over these kk days.

3 2
0 1 0
9

Hint

Sample Explanation

On the first day, the sequence is a={0,1,0}a=\{0,1,0\}. We walk 33 steps and spin 22 times, so the time is 55.

On the second day, the sequence is a={1,0,0}a=\{1,0,0\}. We walk 33 steps and spin 11 time, so the time is 44.

Constraints

This problem uses subtasks for bundled judging. The score for each subtask is as follows: | Subtask | Range | Score | | :----------: | :----------: | :----------: | | 00 | 1n,k2×1031\le n,k\le 2\times 10^3 | 3030 | | 11 | 1n,k2×1061\le n,k\le 2\times 10^6 | 7070 |

For all data, 1n,k2×1061\le n,k\le2\times10^6 and ai{0,1}a_i\in\{0,1\}.

Translated by ChatGPT 5