Time Limit: 1000 ms Memory Limit: 65536 KiB
Given an integer number sequence A of length N (1<=N<=1000), we define f(i,j)=(A[i]+A[i+1]+...+A[j])^2 (i<=j). Now you can split the sequence into exactly M (1<=M<= N) succesive parts, and the cost of a part from A[i] to A[j] is f(i,j). The totle cost is the sum of the cost of each part. Please split the sequence with the minimal cost.
At the first of the input comes an integer t indicates the number of cases to follow. Every case starts with a line containing N ans M. The following N lines are A, A...A[N], respectively. 0<=A[i]<=100 for every 1<=i<=N.
For each testcase, output one line containing an integer number denoting the minimal cost of splitting the sequence into exactly M succesive parts.
1 5 2 1 3 2 4 5