1! Little Tom was bad, and for the punishment he was given the duty to paint the wall. The wall can be presented as a 2D array with N rows and M columns. Tom has a very strange brush with which he can in either row give the paint or the first Ai columns or the last
M-Ai columns. To Tom, each column is boring as much as the product of the number of painted and unpainted fields in that column. The total wall boredom is equal to the sum total of the boredom of all columns. Help Tom and calculate the least possible wall boredom after staining.
Input 1:
2 3
1
2
Output 1: 1
Input 2:
4 4
2
1
4
1
Output 2: 6
~~~~~~~~~~~~~~~~~~~~~~~~
Problem 2:
The notorious master of all rodents, Black, intends to subjugate the whole world. However, a good part of Perine Farm will serve for now.
Perin's farm can be presented as a matrix M of dimension N × N where Mij field contains one number - the sort of apples that Pera breeds in that field. It is known that Pera marks the varieties with some numbers between 1 and K.
Strange roads are rocks, and Cirlet's regular army can subjugate only the best territories. We say that the territory is suitable if it is rectangular in shape, it contains only one variety of apples and this variety is located only within that territory.
Hiring elite rats costs too much, and Çrleta is interested in the extent to which Perina Farm has a suitable territory (he himself does not know why). Since Ćrle is too busy eating cheese, he asked you to designate it instead
Input:
5 10
3 2 2 1 4
3 2 2 7 4
8 2 2 1 3
8 8 9 9 9
8 8 1 5 1
Output: 5
explain output: good parts of farm are those who contains numbers 2, 4, 5, 7 and 9
CAN SOMEONE DO THIS IN C?