Codeforces Round 939 (Div. 2)
D
Nene and the Mex Operator
Codeforces
2000
原题
← CE1 →
翻译中…

Nene gave you an array of integers $a_1, a_2, \ldots, a_n$ of length $n$.

翻译中…

You can perform the following operation no more than $5\cdot 10^5$ times (possibly zero):

翻译中…
  • Choose two integers $l$ and $r$ such that $1 \le l \le r \le n$, compute $x$ as $\operatorname{MEX}(\{a_l, a_{l+1}, \ldots, a_r\})$, and simultaneously set $a_l:=x, a_{l+1}:=x, \ldots, a_r:=x$.
翻译中…

Here, $\operatorname{MEX}$ of a set of integers $\{c_1, c_2, \ldots, c_k\}$ is defined as the smallest non-negative integer $m$ which does not occur in the set $c$.

翻译中…

Your goal is to maximize the sum of the elements of the array $a$. Find the maximum sum and construct a sequence of operations that achieves this sum. Note that you don't need to minimize the number of operations in this sequence, you only should use no more than $5\cdot 10^5$ operations in your solution.

翻译中…

Input

翻译中…

The first line contains an integer $n$ ($1 \le n \le 18$) — the length of the array $a$.

翻译中…

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\leq a_i \leq 10^7$) — the array $a$.

翻译中…

Output

翻译中…

In the first line, output two integers $s$ and $m$ ($0\le m\le 5\cdot 10^5$) — the maximum sum of elements of the array $a$ and the number of operations in your solution.

翻译中…

In the $i$-th of the following $m$ lines, output two integers $l$ and $r$ ($1 \le l \le r \le n$), representing the parameters of the $i$-th operation.

翻译中…

It can be shown that the maximum sum of elements of the array $a$ can always be obtained in no more than $5 \cdot 10^5$ operations.

翻译中…

Note

翻译中…

In the first example, after the operation with $l=1$ and $r=2$ the array $a$ becomes equal to $[2,2]$. It can be shown that it is impossible to achieve a larger sum of the elements of $a$, so the answer is $4$.

翻译中…

In the second example, the initial sum of elements is $13$ which can be shown to be the largest.

翻译中…

In the third example, the array $a$ changes as follows:

翻译中…
  • after the first operation ($l=3$, $r=3$), the array $a$ becomes equal to $[1,100,0,1]$;
  • after the second operation ($l=3$, $r=4$), the array $a$ becomes equal to $[1,100,2,2]$.
翻译中…

It can be shown that it is impossible to achieve a larger sum of the elements of $a$, so the answer is $105$.

翻译中…

样例

Input #1
2
0 1
Output #1
4 1
1 2
InputCopy OutputCopy
Input #2
3
1 3 9
Output #2
13 0
InputCopy OutputCopy
Input #3
4
1 100 2 1
Output #3
105 2
3 3
3 4
InputCopy OutputCopy
Input #4
1
0
Output #4
1 1
1 1
InputCopy OutputCopy
题目信息
题号
1956D
时间限制
2 s
内存限制
256 MB
标签
位运算
暴力
构造
分治
动态规划
贪心
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。