Add and Swap

AtCoder
IDarc187_a
Time2000ms
Memory256MB
Difficulty
You are given integers $N$, $K$, and a sequence $A = (A_1, \ldots, A_N)$ of length $N$. Determine whether it is possible to make $A$ non-decreasing by performing the following operation at most $500000$ times, and if possible, provide one sequence of operations to do so. * Choose an integer $i$ between $1$ and $N-1$, inclusive. Simultaneously replace $A_i$ with $A_{i+1} + K$, and $A_{i+1}$ with $A_i$. ## Constraints * All input numbers are integers. * $2 \leq N \leq 50$ * $1 \leq K \leq 50$ * $1 \leq A_i \leq 50$ ## Input The input is given from Standard Input in the following format: $N$ $K$ $A_1$ $\ldots$ $A_N$ [samples]
Samples
Input #1
3 2
3 6 4
Output #1
Yes
1
2

Let us perform the operation with $i=2$. This simultaneously replaces $A_2$ with $A_3 + 2 = 6$, and $A_3$ with $A_2 = 6$, making $A = (3,6,6)$.
Now $A$ is non-decreasing, so this output satisfies the conditions.
Input #2
3 3
1 5 8
Output #2
Yes
2
2 2

It is not necessary to minimize the number of operations.
API Response (JSON)
{
  "problem": {
    "name": "Add and Swap",
    "description": {
      "content": "You are given integers $N$, $K$, and a sequence $A = (A_1, \\ldots, A_N)$ of length $N$. Determine whether it is possible to make $A$ non-decreasing by performing the following operation at most $50000",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc187_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given integers $N$, $K$, and a sequence $A = (A_1, \\ldots, A_N)$ of length $N$.\nDetermine whether it is possible to make $A$ non-decreasing by performing the following operation at most $50000...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments