View Code of Problem 182

#include <iostream>
#include <cstring>
using namespace std;
int a[110][110],b[110];
int main(){
	int n,maxn;
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	maxn=a[0][0];
	for(int i=0;i<n;i++){
		memset(b,0,sizeof(b));
		for(int j=i;j<n;j++){
			int sum=0;
			for(int k=0;k<n;k++){
				b[k]+=a[j][k];
				if(sum>0)
					sum+=b[k];
				else
					sum=b[k];
				maxn=max(maxn,sum);
			}
		}
	}
	cout<<maxn;
	return 0;
}

Double click to view unformatted code.


Back to problem 182