{"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 from the array.\n\nFor each $x=1,2,\\ldots,M$, solve the following problem:\n\n*   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.\n\nNote that the sum of elements of an empty array is $0$.\n\n## Constraints\n\n*   $1 \\leq N,M \\leq 3000$\n*   $1 \\leq a_i \\leq 3000$\n*   All values in the input are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ $M$\n$a_1$ $\\ldots$ $a_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc275_f","tags":[],"sample_group":[["4 5\n1 2 3 4","1\n2\n1\n1\n1\n\nThe followings are examples of minimum number of operations that achieve the goal.\n\n*   For $x=1$, delete $a_2,a_3,a_4$, and the sum of elements of $A$ becomes $x$.\n*   For $x=2$, delete $a_3,a_4$, then delete $a_1$, and the sum of elements of $A$ becomes $x$.\n*   For $x=3$, delete $a_3,a_4$, and the sum of elements of $A$ becomes $x$.\n*   For $x=4$, delete $a_1,a_2,a_3$, and the sum of elements of $A$ becomes $x$.\n*   For $x=5$, delete $a_2,a_3$, and the sum of elements of $A$ becomes $x$."],["1 5\n3","\\-1\n-1\n0\n-1\n-1"],["12 20\n2 5 6 5 2 1 7 9 7 2 5 5","2\n1\n2\n2\n1\n2\n1\n2\n2\n1\n2\n1\n1\n1\n2\n2\n1\n1\n1\n1"]],"created_at":"2026-03-03 11:01:14"}}