Buildings are Colorful!

AtCoder
IDs8pc_4_b
Time1000ms
Memory256MB
Difficulty
There are $N$ buildings along the line. The $i$\-th building from the left is colored in color $i$, and its height is currently $a_i$ meters. Chokudai is a mayor of the city, and he loves colorful thigs. And now he wants to see at least $K$ buildings from the left. You can increase height of buildings, but it costs $1$ yens to increase $1$ meters. It means you cannot make building that height is not integer. You cannot decrease height of buildings. Calculate the minimum cost of satisfying Chokudai's objective. Note: "Building $i$ can see from the left" means there are no $j$ exists that (height of building $j$) ≥ (height of building $i$) and $j < i$. ## Input Format $N$ $K$ $a_1$ $a_2$ $a_3$ ... $a_N$ [samples]
API Response (JSON)
{
  "problem": {
    "name": "Buildings are Colorful!",
    "description": {
      "content": "There are $N$ buildings along the line. The $i$\\-th building from the left is colored in color $i$, and its height is currently $a_i$ meters.   Chokudai is a mayor of the city, and he loves colorful t",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "s8pc_4_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $N$ buildings along the line. The $i$\\-th building from the left is colored in color $i$, and its height is currently $a_i$ meters.  \nChokudai is a mayor of the city, and he loves colorful t...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments