public static int MinAdjustmentCost(List<Integer> A, int target) {
        // write your code here
        int min=Integer.MAX_VALUE, max=Integer.MIN_VALUE;
        for (int a:A) {
            min=Math.min(min, a);
            max=Math.max(max, a);
        }
        int off=min-target;
        int n=max-min+target*2+1;
        int[]c=new int [n], p=new int[n];
        for (int i=0;i<A.size();++i) {
            Arrays.fill(c,Integer.MAX_VALUE/2);
            for (int j=0; j<c.length;++j) {
                for (int k=-target; k<=target;++k) {
                    if (j+k>=0&&j+k<p.length)
                        c[j]=Math.min(c[j],p[j+k]+Math.abs(off+j-A.get(i)));
                }
            }
            System.arraycopy(c, 0, p, 0, c.length);
        }
        min=Integer.MAX_VALUE;
        for (int a:p)
            min=Math.min(a,min);
        return min;
    }