Paint walls
Practice
2 (1 votes)
Arrays
Implementation
Math basic
Basics of implementation
Basic programming
Problem
89% Success 2769 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

A wall in your room can be considered as a two dimensional matrix of \(n\) rows and \(m\) columns.

Initally, the wall is painted white and repainting any cell \((i,\ j)\) has a cost \(a_{ij}\). You want to paint a HackerEarth logo of dimension two rows and \(k\) columns \((2 \times K)\) in the minimum cost possible.The logo can be painted either horizontally or vertically. You are required to determine the minimum cost you must pay to get the wall painted.

If there is no possible way to get the wall painted, then print \(-1\). Otherwise, print the minimum cost.

Note: The logo can be painted in form of \(2 \times K\) or \(K \times 2\) that provides you the minimum cost.

Input forrmat

  • First line: A single integer \(T\) denoting the number of test cases
  • For each test case:
    • First line: Three integers \(n,\ m,\ and\ k\)
    • Next \(n\) lines contains \(m\) space-separated numbers denoting the cost of repainting any cells

Output format

For each test case, print the minimum cost to repaint the wall. If it is not possible to repaint a wall, then print \(-1\).

Constraints

\(1\le T\le 3\\ 1\le n,\ m,\ k\le 1000\\ 0\le a_{ij}\le 100000\ for\ all\ i\ from\ [1,\ n]\ and\ for\ all\ j\ from\ [1,\ m]\\ \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
3 votes
Tags:
BFSDynamic Programming
Editorial

Login to unlock the editorial