QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 512 MB 満点: 100

#9563. There Should Be Snow in the Human World Again

統計

A street of length $n$ is covered in snow, divided into $n$ segments. The amount of snow in the $i$-th segment is $a_i$, where $0 \le a_i \le m$ and $a_i$ is an integer.

Tianyi and Yanhe want to clear the snow. Each time they perform a cleaning operation, they have two choices:

  • Tianyi walks from position 1 to position $x$, clears $c$ amount of snow at $x$, and walks back to position 1. Because of the movement on the snow, the snow amount in positions $1 \sim x$ decreases by 1. Specifically, $\forall i \in [1, x-1], a_i := a_i - 1$, and $a_x := a_x - c - 1$.
  • Yanhe walks from position $n$ to position $x$, clears $c$ amount of snow at $x$, and walks back to position $n$. Because of the movement on the snow, the snow amount in positions $x \sim n$ decreases by 1. Specifically, $\forall i \in [x+1, n], a_i := a_i - 1$, and $a_x := a_x - c - 1$.

At any time, the amount of snow is $\max(0, \text{current amount})$.

Tianyi and Yanhe want to know the minimum number of cleaning operations required (i.e., minimizing the total number of operations performed by both) to clear all the snow, such that $\forall i \in [1, n], a_i = 0$.

Input

The input contains multiple test cases.

The first line contains two integers $T$ and $tid$, where $T$ is the number of test cases and $tid$ is the subtask ID (the subtask ID for the sample is 0).

For each test case:

The first line contains three integers $n, m, c$.

The second line contains $n$ integers $a_1 \sim a_n$.

Output

For each test case, output a single integer representing the answer.

Examples

Input 1

1 0
5 5 1
1 3 2 3 1

Output 1

2

Note

Tianyi walks to position 4 to clean, and the snow amounts become $[0, 2, 1, 1, 1]$.

Yanhe walks to position 2 to clean, and the snow amounts become $[0, 0, 0, 0, 0]$.

A total of 2 cleaning operations.

Example 2

See snow.in and snow.ans in the additional files. This example contains 100 test cases with $n = 10, m = 10$.

Constraints

For $100\%$ of the data, $1 \le T \le 10^5$, $1 \le n, m \le 5 \times 10^5$, $\sum n, \sum m \le 10^6$, $0 \le a_i \le m$, $0 \le c \le 5 \times 10^5$.

Subtask ID $n$ $m$ Special Constraints Score Dependencies
1 $\le 5 \times 10^5$ $\le 5 \times 10^5$ $c = 0$ 2
2 $\le 2$ None 3
3 $\le 5$ $\le 5$ $T \le 10^5$ 4
4 $\le 50$ $\le 50$ $\sum n, \sum m \le 200$ 10 3
5 $\le 300$ $\le 300$ $\sum n, \sum m \le 600$ 10 4
6 $\le 2\,000$ $\le 2\,000$ $\sum n, \sum m \le 4000$ 10 5
7 $\le 5 \times 10^4$ $\le 5 \times 10^4$ $c \le 20, \sum n, \sum m \le 10^5$ 20
8 $\sum n, \sum m \le 10^5$ 15 6, 7
9 $\le 5 \times 10^5$ $\le 5 \times 10^5$ $c \le 20$ 10 1, 7
10 None 15 2, 8, 9

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download
#650EditorialOpen#9563 的一种新的做法 | New Editorial for Problem #9563liuxy23572026-01-06 09:10:16View

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.