import java.util.*; import java.io.*; //comment out when submitting public class c { // Scanner in = new Scanner(System.in); static Scanner in = null; public static void main(String[] args) { //comment out this part try { File file = new File("input.txt"); in = new Scanner(file); } catch(FileNotFoundException e) { System.out.println("error"); } new c().go(); } private void go() { //read the input int n = in.nextInt(); int d = in.nextInt(); int[] prices = new int[n]; for(int i = 0; i < n; i++) { prices[i] = in.nextInt(); } //initialize dp table int[][] dpTable = new int[n][d+1]; int sum = 0; for(int i = 0; i < n; i++) { sum = sum + prices[i]; dpTable[i][0] = round(sum); } for(int j = 0; j < d + 1; j++) { dpTable[0][j] = dpTable[0][0]; } int[][] sumTable = new int[n][n-1]; for(int i = 0; i < n; i ++) { for(int k = 0; k < n-1; k++) { sumTable[i][k] = -1; } } for(int j = 1; j < d + 1; j++) { for(int i = 1; i < n; i++) { int minCost = Integer.MAX_VALUE; for(int k = 0; k < i; k++) { int cost = 0; if(sumTable[i][k] != -1) { cost = dpTable[k][j-1] + round(sumTable[i][k]); } else{ int restSum = sumUp(prices, k, i); cost = dpTable[k][j-1] + round(restSum); sumTable[i][k] = restSum; } if (cost < minCost) { minCost = cost; } } dpTable[i][j] = minCost; } } // for(int[] row: dpTable) { // System.out.println(Arrays.toString(row)); // } int result = Integer.MAX_VALUE; for(int c: dpTable[n-1]) { if(c < result) { result = c; } } System.out.println(result); } private int sumUp(int[] price, int k, int i) { int sum = 0; for(int j = k + 1; j <= i; j++) { sum = sum + price[j]; } return sum; } private int round(int n) { return (n + 5) / 10 * 10; } }