Array division - MarisaOJ: Marisa Online Judge

Array division

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ of $n$ integers. The cost of a subarray $A_{l...r}$ is $(A_l-A_r)^2$. Your task is dividing array $A$ in $k$ subarrays so that the total cost is minimized. ### Input - The first line contains two integers $n,k$. - The second line contains $n$ integer $A_i$. ### Output - Print an integer is the minimum cost. ### Constraints - $1 \le n \le 10^4$. - $1 \le k \le min(100,n)$. - $1 \le A_i \le 10^9$. ### Example Input: ``` 5 2 2 3 1 5 4 ``` Output: ``` 1 ```
Topic
Data structure
Dynamic Programming
Geometry
Rating 2000
Source CS Academy
Solution (0) Solution