{"id":"7c93ce0a-7cf5-4e59-94d8-d3676c6dd0e6","name":"Paint House","description":"1. You are given a number n, representing the number of houses.\r\n2. In the next n rows, you are given 3 space separated numbers representing the cost of painting nth house with red or blue or green color.\r\n3. You are required to calculate and print the minimum cost of painting all houses without painting any consecutive house with same color.","inputFormat":"A number n\r\nn1red n1blue n1green\r\nn2red n2blue n2green\r\n.. n number of elements","outputFormat":"A number representing the minimum cost of painting all houses without painting any consecutive house with same color.","constraints":"1 &lt;= n &lt;= 1000\r\n0 &lt;= n1red, n1blue, .. &lt;= 1000","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\r\nusing namespace std;\r\n\r\nint main(){\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n}"},"python":{"code":"print()"}},"points":10,"difficulty":"easy","sampleInput":"4\r\n1 5 7\r\n5 8 4\r\n3 2 9\r\n1 2 4","sampleOutput":"8","questionVideo":"https://www.youtube.com/embed/kh48JLieeW8?end=84","hints":[],"associated":[{"id":"2b7926d2-b819-4149-b5b5-d78792a2061a","name":"From where we will traverse the loop?","slug":"from-where-we-will-traverse-the-loop","type":4},{"id":"30949bb1-638a-4aea-8e80-3e1044cd51e2","name":"What will be the minimum cost for the 1st house?","slug":"what-will-be-the-minimum-cost-for-the-1st-house","type":4},{"id":"73a317ae-8d1c-4b13-aea2-76655105016f","name":"What will be our minimum cost of paint i.e. final answer ?","slug":"what-will-be-our-minimum-cost-of-paint-i-e-final-answer","type":4},{"id":"8d8c97bd-9aa0-4245-a0cd-18844392557c","name":"What will be the size of the array used in dp in above question?","slug":"what-will-be-the-size-of-the-array-used-in-dp-in-above-question","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"2dcfe15e-08c5-49b5-9f25-3b8309450bc9","name":"Paint House","slug":"paint-house","type":1}],"next":{"id":"72d7a2f3-1cc4-402e-a2ae-9abd1b18691a","name":"Paint House","type":3,"slug":"paint-house"},"prev":{"id":"0ae78328-c5a0-4d7a-ad0a-9e2f955c555c","name":"Maximum Sum Non Adjacent Elements","type":3,"slug":"maximum-sum-non-adjacent-elements"}}}

Paint House

1. You are given a number n, representing the number of houses. 2. In the next n rows, you are given 3 space separated numbers representing the cost of painting nth house with red or blue or green color. 3. You are required to calculate and print the minimum cost of painting all houses without painting any consecutive house with same color.

{"id":"7c93ce0a-7cf5-4e59-94d8-d3676c6dd0e6","name":"Paint House","description":"1. You are given a number n, representing the number of houses.\r\n2. In the next n rows, you are given 3 space separated numbers representing the cost of painting nth house with red or blue or green color.\r\n3. You are required to calculate and print the minimum cost of painting all houses without painting any consecutive house with same color.","inputFormat":"A number n\r\nn1red n1blue n1green\r\nn2red n2blue n2green\r\n.. n number of elements","outputFormat":"A number representing the minimum cost of painting all houses without painting any consecutive house with same color.","constraints":"1 &lt;= n &lt;= 1000\r\n0 &lt;= n1red, n1blue, .. &lt;= 1000","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\r\nusing namespace std;\r\n\r\nint main(){\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n}"},"python":{"code":"print()"}},"points":10,"difficulty":"easy","sampleInput":"4\r\n1 5 7\r\n5 8 4\r\n3 2 9\r\n1 2 4","sampleOutput":"8","questionVideo":"https://www.youtube.com/embed/kh48JLieeW8?end=84","hints":[],"associated":[{"id":"2b7926d2-b819-4149-b5b5-d78792a2061a","name":"From where we will traverse the loop?","slug":"from-where-we-will-traverse-the-loop","type":4},{"id":"30949bb1-638a-4aea-8e80-3e1044cd51e2","name":"What will be the minimum cost for the 1st house?","slug":"what-will-be-the-minimum-cost-for-the-1st-house","type":4},{"id":"73a317ae-8d1c-4b13-aea2-76655105016f","name":"What will be our minimum cost of paint i.e. final answer ?","slug":"what-will-be-our-minimum-cost-of-paint-i-e-final-answer","type":4},{"id":"8d8c97bd-9aa0-4245-a0cd-18844392557c","name":"What will be the size of the array used in dp in above question?","slug":"what-will-be-the-size-of-the-array-used-in-dp-in-above-question","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"2dcfe15e-08c5-49b5-9f25-3b8309450bc9","name":"Paint House","slug":"paint-house","type":1}],"next":{"id":"72d7a2f3-1cc4-402e-a2ae-9abd1b18691a","name":"Paint House","type":3,"slug":"paint-house"},"prev":{"id":"0ae78328-c5a0-4d7a-ad0a-9e2f955c555c","name":"Maximum Sum Non Adjacent Elements","type":3,"slug":"maximum-sum-non-adjacent-elements"}}}
plane

Editor


Loading...

Paint House

easy

1. You are given a number n, representing the number of houses. 2. In the next n rows, you are given 3 space separated numbers representing the cost of painting nth house with red or blue or green color. 3. You are required to calculate and print the minimum cost of painting all houses without painting any consecutive house with same color.

Constraints

1 <= n <= 1000 0 <= n1red, n1blue, .. <= 1000

Format

Input

A number n n1red n1blue n1green n2red n2blue n2green .. n number of elements

Output

A number representing the minimum cost of painting all houses without painting any consecutive house with same color.

Example

Sample Input

4 1 5 7 5 8 4 3 2 9 1 2 4

Sample Output

8

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode