Skip to content

Instantly share code, notes, and snippets.

@fardinabir
Created March 30, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fardinabir/c5728f1620eb1b8bc0c2a6b985711bd2 to your computer and use it in GitHub Desktop.
Save fardinabir/c5728f1620eb1b8bc0c2a6b985711bd2 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define mxs 100005
#define ll long long int
#define print_case printf("Case %lld: ",ts++)
using namespace std;
ll arr[100005],n,m,cnt;
ll qube[21][21][21],cum[21][21][21],sum[21];
ll kadane(ll c)
{
ll i,mx=sum[1],s=0;
for(i=1;i<=c;i++)
{
s+=sum[i];
mx=max(mx,s);
s=s<0?0:s;
}
return mx;
}
ll sum_at(int xs,int xe,int ys,int ye,int i)
{
return qube[xe][ye][i]-qube[xe][ys-1][i]-qube[xs-1][ye][i]+qube[xs-1][ys-1][i];
}
int main()
{
ll t,k,a,b,d,x,y,i,q,j,l,s,c,ans,mx=INT_MIN,mn=INT_MAX,ts=1;
cin>>t;
while(t--)
{
cin>>a>>b>>c;
mx=INT_MIN;
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
for(k=1;k<=c;k++)
{
cin>>qube[i][j][k];
mx=max(mx,qube[i][j][k]);
qube[i][j][k]+=qube[i-1][j][k]+qube[i][j-1][k]-qube[i-1][j-1][k];
}
}
}
int xs,xe,ys,ye;
for(xs=1;xs<=a;xs++)
{
for(xe=xs;xe<=a;xe++)
{
for(ys=1;ys<=b;ys++)
{
for(ye=ys;ye<=b;ye++)
{
for(i=1;i<=c;i++)
{
sum[i]=sum_at(xs,xe,ys,ye,i);
}
mx=max(mx,kadane(c));
}
}
}
}
cout<<mx<<endl;
if(t)
cout<<endl;
}
return 0;
}
/*
2
2 2 2
-1 2 0 -3 -2 -1 1 5
2 2 2
-1 2 0 -3 -2 -1 1 5
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment