Create a gist now

Instantly share code, notes, and snippets.

@arukuka /ICPC2017C.cpp Secret
Created Jul 14, 2017

What would you like to do?
#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