Bracket Score 2

AtCoder
IDarc120_d
Time2000ms
Memory256MB
Difficulty
Let us define **balanced parenthesis string** as a string satisfying one of the following conditions: * An empty string. * A concatenation of $s$ and $t$ in this order, for some non-empty balanced parenthesis strings $s$ and $t$. * A concatenation of `(`, $s$, `)` in this order, for some balanced parenthesis string $s$. Also, let us say that the $i$\-th and $j$\-th characters of a parenthesis string $s$ is **corresponding** to each other when all of the following conditions are satisfied: * $1 \le i < j \le |s|$. * $s_i = $ `(`. * $s_j = $ `)`. * The string between the $i$\-th and $j$\-th characters of $s$, excluding the $i$\-th and $j$\-th characters, is a balanced parenthesis string. You are given a sequence of length $2N$: $A = (A_1, A_2, A_3, \dots, A_{2N})$. Let us define the **score** of a balanced parenthesis string $s$ of length $2N$ as the sum of $|A_i - A_j|$ over all pairs $(i, j)$ such that the $i$\-th and $j$\-th characters of $s$ are corresponding to each other. Among the balanced parenthesis strings of length $2N$, find one with the maximum score. ## Constraints * $1 \le N \le 2 \times 10^5$ * $1 \le A_i \le 10^9$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $A_3$ $\dots$ $A_{2N}$ [samples]
Samples
Input #1
2
1 2 3 4
Output #1
(())

There are two balanced parenthesis strings of length $4$: `(())` and `()()`, with the following scores:

*   `(())`: $|1 - 4| + |2 - 3| = 4$
*   `()()`: $|1 - 2| + |3 - 4| = 2$

Thus, `(())` is the only valid answer.
Input #2
2
2 3 2 3
Output #2
()()

`(())` and `()()` have the following scores:

*   `(())` : $|2 - 3| + |3 - 2| = 2$
*   `()()` : $|2 - 3| + |2 - 3| = 2$

Thus, either is a valid answer in this case.
API Response (JSON)
{
  "problem": {
    "name": "Bracket Score 2",
    "description": {
      "content": "Let us define **balanced parenthesis string** as a string satisfying one of the following conditions: *   An empty string. *   A concatenation of $s$ and $t$ in this order, for some non-empty balance",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc120_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Let us define **balanced parenthesis string** as a string satisfying one of the following conditions:\n\n*   An empty string.\n*   A concatenation of $s$ and $t$ in this order, for some non-empty balance...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments