-
-
Save arukuka/0b86447f95cacd49e540a7ab174ed588 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int mas[11][11]; | |
int outerMin(int i, int j, int k, int l) { | |
int mini = 1000000; | |
for(int a = i; a <= j; a++) { | |
mini = min(min(mini, mas[a][k]), mas[a][l]); | |
} | |
for(int b = k; b <= l; b++) { | |
mini = min(min(mini, mas[i][b]), mas[j][b]); | |
} | |
return mini; | |
} | |
int main() { | |
int h, w; | |
while(cin >> h >> w, h) { | |
int ans = 0; | |
for(int i = 0; i < h; i++) { | |
for(int j = 0; j < w; j++) { | |
cin >> mas[i][j]; | |
} | |
} | |
for(int i = 0; i < h; i++) { | |
for(int j = i + 2; j < h; j++) { | |
for(int k = 0; k < w; k++) { | |
for(int l = k + 2; l < w; l++) { | |
int outerM = outerMin(i, j, k, l); | |
int innerMax = -1000; | |
int sum = 0, cnt = 0; | |
for(int m = i + 1; m < j; m++) { | |
for(int n = k + 1; n < l; n++) { | |
// cout << mas[m][n] << endl; | |
innerMax = max(innerMax, mas[m][n]); | |
sum += mas[m][n]; | |
cnt++; | |
} | |
} | |
//cout << outerM << " " << innerMax << endl; | |
if(outerM > innerMax) { | |
ans = max(ans, outerM * cnt - sum); | |
} | |
} | |
} | |
} | |
} | |
cout << ans << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment