± Increasing Sequence

AtCoder
IDarc153_c
Time2000ms
Memory256MB
Difficulty
You are given a sequence of length $N$, $A = (A_1, \ldots, A_N)$, consisting of $1$ and $-1$. Determine whether there is an integer sequence $x = (x_1, \ldots, x_N)$ that satisfies all of the following conditions, and print one such sequence if it exists. * $|x_i| \leq 10^{12}$ for every $i$ ($1\leq i\leq N$). * $x$ is strictly increasing. That is, $x_1 < \cdots < x_N$. * $\sum_{i=1}^N A_ix_i = 0$. ## Constraints * $1\leq N\leq 2\times 10^5$ * $A_i \in \lbrace 1, -1\rbrace$ ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $\ldots$ $A_N$ [samples]
Samples
Input #1
5
-1 1 -1 -1 1
Output #1
Yes
-3 -1 4 5 7

For this output, we have $\sum_{i=1}^NA_ix_i= -(-3) + (-1) - 4 - 5 + 7 = 0$.
Input #2
1
-1
Output #2
Yes
0
Input #3
2
1 -1
Output #3
No
API Response (JSON)
{
  "problem": {
    "name": "± Increasing Sequence",
    "description": {
      "content": "You are given a sequence of length $N$, $A = (A_1, \\ldots, A_N)$, consisting of $1$ and $-1$. Determine whether there is an integer sequence $x = (x_1, \\ldots, x_N)$ that satisfies all of the followin",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc153_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a sequence of length $N$, $A = (A_1, \\ldots, A_N)$, consisting of $1$ and $-1$.\nDetermine whether there is an integer sequence $x = (x_1, \\ldots, x_N)$ that satisfies all of the followin...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments