A. Max or Min

Codeforces
IDCF10239A
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Kevin has $n$ integers $a_1, a_2, \\dots, a_n$ arranged in a *circle*. That is, the numbers $a_i$ and $a_{i + 1}$ ($1 <= i < n$) are neighbors. The numbers $a_1$ and $a_n$ are neighbors as well. Therefore, each number has exactly two neighbors. In one minute, Kevin can set $a_i$ to the minimum among three numbers: $a_i$ and it's two neighbors. Alternatively, Kevin can set $a_i$ to the maximum among the same numbers. For example, if $a_i = 5$ and $a_i$ has two neighbors $3$ and $2$, and Kevin performs the minimum operation, $a_i$ will be equal to $2$. However, if he performs the maximum operation, $a_i$ will remain $5$. For each $x$ from $1$ to $m$, find the minimum number of minutes to make all numbers equal $x$, or determine that it is impossible to do so. The first line contains two integers $n$ and $m$ ($3 <= n <= 2 dot.op 10^5$, $1 <= m <= 2 dot.op 10^5$) — the number of integers in the circle, and the number of integers you need to find answers for. The second line contains $n$ integers $a_1, a_2, \\dots, a_n$ ($1 <= a_i <= m$) — the integers in the circle. Print $m$ integers. The $i$-th integer should be equal to the minimum number of minutes that are needed to make all numbers equal $i$ or $-1$ if it's impossible. To make all numbers equal $2$ Kevin needs at least $5$ minutes. One of the possible sequence of operations: ## Input The first line contains two integers $n$ and $m$ ($3 <= n <= 2 dot.op 10^5$, $1 <= m <= 2 dot.op 10^5$) — the number of integers in the circle, and the number of integers you need to find answers for.The second line contains $n$ integers $a_1, a_2, \\dots, a_n$ ($1 <= a_i <= m$) — the integers in the circle. ## Output Print $m$ integers. The $i$-th integer should be equal to the minimum number of minutes that are needed to make all numbers equal $i$ or $-1$ if it's impossible. [samples] ## Note To make all numbers equal $2$ Kevin needs at least $5$ minutes. One of the possible sequence of operations: Apply min operation to $a_6$, it will be equal to $2$. Apply max operation to $a_4$, it will be equal to $2$. Apply max operation to $a_3$, it will be equal to $5$. Apply min operation to $a_2$, it will be equal to $2$. Apply min operation to $a_3$, it will be equal to $2$.
**Definitions** Let $ x \in \mathbb{Z} $ denote the number of sandwiches Bashar wants to buy. **Constraints** $ 1 \le x \le 30 $ **Objective** Compute the total cost in JDs: $$ C = 2x $$
API Response (JSON)
{
  "problem": {
    "name": "A. Max or Min",
    "description": {
      "content": "Kevin has $n$ integers $a_1, a_2, \\\\dots, a_n$ arranged in a *circle*. That is, the numbers $a_i$ and $a_{i + 1}$ ($1 <= i < n$) are neighbors. The numbers $a_1$ and $a_n$ are neighbors as well. There",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10239A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Kevin has $n$ integers $a_1, a_2, \\\\dots, a_n$ arranged in a *circle*. That is, the numbers $a_i$ and $a_{i + 1}$ ($1 <= i < n$) are neighbors. The numbers $a_1$ and $a_n$ are neighbors as well. There...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ x \\in \\mathbb{Z} $ denote the number of sandwiches Bashar wants to buy.\n\n**Constraints**  \n$ 1 \\le x \\le 30 $\n\n**Objective**  \nCompute the total cost in JDs:  \n$$\nC = 2x\n$$...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments