Erase Subarrays

AtCoder
IDabc275_f
Time2000ms
Memory256MB
Difficulty
You are given an integer array $A=(a_1,a_2,\ldots,a_N)$. You may perform the following operation any number of times (possibly zero). * Choose a nonempty contiguous subarray of $A$, and delete it from the array. For each $x=1,2,\ldots,M$, solve the following problem: * Find the minimum possible number of operations to make the sum of elements of $A$ equal $x$. If it is impossible to make the sum of elements of $A$ equal $x$, print `-1` instead. Note that the sum of elements of an empty array is $0$. ## Constraints * $1 \leq N,M \leq 3000$ * $1 \leq a_i \leq 3000$ * All values in the input are integers. ## Input The input is given from Standard Input in the following format: $N$ $M$ $a_1$ $\ldots$ $a_N$ [samples]
Samples
Input #1
4 5
1 2 3 4
Output #1
1
2
1
1
1

The followings are examples of minimum number of operations that achieve the goal.

*   For $x=1$, delete $a_2,a_3,a_4$, and the sum of elements of $A$ becomes $x$.
*   For $x=2$, delete $a_3,a_4$, then delete $a_1$, and the sum of elements of $A$ becomes $x$.
*   For $x=3$, delete $a_3,a_4$, and the sum of elements of $A$ becomes $x$.
*   For $x=4$, delete $a_1,a_2,a_3$, and the sum of elements of $A$ becomes $x$.
*   For $x=5$, delete $a_2,a_3$, and the sum of elements of $A$ becomes $x$.
Input #2
1 5
3
Output #2
\-1
-1
0
-1
-1
Input #3
12 20
2 5 6 5 2 1 7 9 7 2 5 5
Output #3
2
1
2
2
1
2
1
2
2
1
2
1
1
1
2
2
1
1
1
1
API Response (JSON)
{
  "problem": {
    "name": "Erase Subarrays",
    "description": {
      "content": "You are given an integer array $A=(a_1,a_2,\\ldots,a_N)$.   You may perform the following operation any number of times (possibly zero). *   Choose a nonempty contiguous subarray of $A$, and delete it",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc275_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer array $A=(a_1,a_2,\\ldots,a_N)$.  \nYou may perform the following operation any number of times (possibly zero).\n\n*   Choose a nonempty contiguous subarray of $A$, and delete it...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments