Minimum money needed all test cases failing

import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int w = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
System.out.println(minMoneyBU(a, w));
}

public static int minMoneyBU(int a[], int w) {
	int[][] strg = new int[a.length + 1][w + 1];
	for (int row = 0; row <= a.length; row++) {
		for (int col = 1; col <= w; col++) {
			if (row == 0) {
				strg[row][col] = Integer.MAX_VALUE;
			} else {
				if (row > col) {
					strg[row][col] = strg[row - 1][col];
				} else {
					strg[row][col] = Math.min(strg[row - 1][col], strg[row][col - row] + a[row - 1]);
				}
			}
		}
	}
	return strg[a.length][w] == Integer.MAX_VALUE ? -1 : strg[a.length][w];
}

}

If you read the problem statement carefully then you will realise that the N value given in input does not represent the size of the array. Infact it is quite useless.
This is a 1D DP problem. The size of the array is W only , not N.
for test case:
5 6
175 155 181 179 41 204
the correct answer is 204 you are getting 216
take number of input equal to W