Codeforces Round #790 (Div. 4) 1676 D. X-Sum Solution
Problem Link: https://codeforces.com/contest/1676/problem/D
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,x,y,i,j,aa,b,c;
cin>>t;
while(t--)
{
c=0;
cin>>x>>y;
int a[x+9][y+9],mx=-1000;
for(i=1; i<=x; i++)
{
for(j=1; j<=y; j++)
{
cin>>a[i][j];
}
}
for(i=1; i<=x; i++)
{
for(j=1; j<=y; j++)
{
c=0;
c+=a[i][j];
for(aa=i+1,b=j+1;aa<=x&&b<=y; aa++,b++)
c+=a[aa][b];
for(aa=i+1,b=j-1; aa<=x&&b>=1; aa++,b--)
c+=a[aa][b];
for(aa=i-1,b=j+1; aa>=1&&b<=y; aa--,b++)
c+=a[aa][b];
for(aa=i-1,b=j-1; aa>=1&&b>=1; aa--,b--)
c+=a[aa][b];
mx=max(c,mx);
}
}
cout<<mx<<endl;
}
}
No comments