問題一覧 > 通常問題

No.3165 [Cherry 7th Tune A] Croissants Continu

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 69
作問者 : 👑 Kazun / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 10259 / 自分の提出
問題文最終更新日: 2025-05-20 00:12:49
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 468 Desire for Approval ~Ash blown by the draft leads to the door to a new beginning~ (順位表) の他の問題:

Problem Visual

▶ Open to reveal the problem visual

Problem Statement

Cherry-chan has some croissants. The flavor of each croissant is represented by an integer between $1$ and $N$, inclusive, and she has $A_i$ croissants of flavor $i$.

Cherry-chan wants to eat as many croissants as possible by repeating the following action $0$ or more times: "choose $1$ croissant from those she has and eat it."

However, since Cherry-chan gets bored easily, she must obey the following rule.

  • Each croissant eaten as the $2$-nd or later must have a flavor different from the croissant eaten immediately before it.

What is the maximum number of croissants Cherry-chan can eat?

Solve $T$ test cases.

Constraints

  • $1 \leq T \leq 10^5$.
  • Constraints for each test case
    • $1 \leq N \leq 3 \times 10^5$.
    • $1 \leq A_i \leq 10^9 \quad (1 \leq i \leq N)$.
  • Constraints for each test file.
    • The sum of $N$ over the $T$ test cases is at most $3 \times 10^5$.

Input

The input is given from standard input. The $1$-st line and onward of the input are as follows.
$T$
$\textrm{Testcase}_1$
$\textrm{Testcase}_2$
$\vdots$
$\textrm{Testcase}_T$
Each test case is given in the following format.
$N$
$A_1$ $A_2$ $\cdots$ $A_N$

Output

The output consists of $T$ lines. On line $t~(1 \leq t \leq T)$, print the answer for the $t$-th test case.

Sample

Sample 1
Input
3
3
1 2 3
1
46
6
15 18 42 87 15 93
Output
6
1
270

  • [Test case $1$] For example, by eating croissants in the following order, Cherry-chan can eat all $6$ croissants she has.
    • flavor $3$ $\to$ flavor $1$ $\to$ flavor $2$ $\to$ flavor $3$ $\to$ flavor $2$ $\to$ flavor $3$
  • [Test case $2$] Cherry-chan can eat $1$ croissant, but she cannot eat $2$ or more. Therefore, the answer is $1$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。