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]; } 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 = dpTable[k][j-1] + round(sumUp(prices, k, i)); if (cost < minCost) { minCost = cost; } } dpTable[i][j] = minCost; } } for(int[] row: dpTable) { System.out.println(Arrays.toString(row)); } System.out.println(dpTable[n-1][d]); } 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; } }