import std.math; + import std.typecons; /* - - You are given a rectangular grid of wells. Each row represents a single well, ? ---- + You are given a rectangular grid of wells. Each row represents a single well, - and each 1 in a row represents a single unit of water. ? ---- + and each 1 in a row represents a single unit of water. - Each well has a corresponding bucket that can be used to extract water from it, ? ---- + Each well has a corresponding bucket that can be used to extract water from it, - and all buckets have the same capacity. ? ---- + and all buckets have the same capacity. - Your task is to use the buckets to empty the wells. ? ---- + Your task is to use the buckets to empty the wells. - Output the number of times you need to lower the buckets. ? ---- + Output the number of times you need to lower the buckets. - - Example 1: ? ---- + Example 1: - >>> max_fill([[0L, 0L, 1L, 0L], [0L, 1L, 0L, 0L], [1L, 1L, 1L, 1L]], 1L) ? ---- + >>> max_fill([[0L, 0L, 1L, 0L], [0L, 1L, 0L, 0L], [1L, 1L, 1L, 1L]], 1L) + 6L - 6L - - Example 2: ? ---- + Example 2: - >>> max_fill([[0L, 0L, 1L, 1L], [0L, 0L, 0L, 0L], [1L, 1L, 1L, 1L], [0L, 1L, 1L, 1L]], 2L) ? ---- + >>> max_fill([[0L, 0L, 1L, 1L], [0L, 0L, 0L, 0L], [1L, 1L, 1L, 1L], [0L, 1L, 1L, 1L]], 2L) + 5L - 5L - - Example 3: ? ---- + Example 3: - >>> max_fill([[0L, 0L, 0L], [0L, 0L, 0L]], 5L) ? ---- + >>> max_fill([[0L, 0L, 0L], [0L, 0L, 0L]], 5L) + 0L - 0L - - Constraints: ? ---- + Constraints: - * all wells have the same length ? ---- + * all wells have the same length - * 1 <= grid.length <= 10^2 ? ---- + * 1 <= grid.length <= 10^2 - * 1 <= grid[:,1].length <= 10^2 ? ---- + * 1 <= grid[:,1].length <= 10^2 - * grid[i][j] -> 0 | 1 ? ---- + * grid[i][j] -> 0 | 1 - * 1 <= capacity <= 10 ? ---- + * 1 <= capacity <= 10 - */ long max_fill(long[][] grid, long capacity)