Sum of Three Terms

AtCoder
IDarc135_b
Time2000ms
Memory256MB
Difficulty
You are given a sequence of $N$ integers $S = (S_1, \ldots, S_N)$. Determine whether there is a sequence of $N+2$ integers $A = (A_1, \ldots, A_{N+2})$ that satisfies the conditions below. * $0\leq A_i$ for every $i$ ($1\leq i\leq N+2$). * $S_i = A_{i} + A_{i+1} + A_{i+2}$ for every $i$ ($1\leq i\leq N$). If it exists, print one such sequence. ## Constraints * $1\leq N\leq 3\times 10^5$ * $0\leq S_i\leq 10^9$ ## Input Input is given from Standard Input from the following format: $N$ $S_1$ $\ldots$ $S_N$ [samples]
Samples
Input #1
5
6 9 6 6 5
Output #1
Yes
0 4 2 3 1 2 2

We can verify that $S_i = A_i + A_{i+1} + A_{i+2}$ for every $i$ ($1\leq i\leq N$), as follows.

*   $6 = 0 + 4 + 2$.
*   $9 = 4 + 2 + 3$.
*   $6 = 2 + 3 + 1$.
*   $6 = 3 + 1 + 2$.
*   $5 = 1 + 2 + 2$.
Input #2
5
0 1 2 1 0
Output #2
No
Input #3
1
10
Output #3
Yes
0 0 10
API Response (JSON)
{
  "problem": {
    "name": "Sum of Three Terms",
    "description": {
      "content": "You are given a sequence of $N$ integers $S = (S_1, \\ldots, S_N)$. Determine whether there is a sequence of $N+2$ integers $A = (A_1, \\ldots, A_{N+2})$ that satisfies the conditions below. *   $0\\leq",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc135_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a sequence of $N$ integers $S = (S_1, \\ldots, S_N)$. Determine whether there is a sequence of $N+2$ integers $A = (A_1, \\ldots, A_{N+2})$ that satisfies the conditions below.\n\n*   $0\\leq...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments