i am trying to solve this problem : Grid Game - Prefix Sum Problem | CodeChef
I trying whatever I can but it’s still showing TLE
here’s my code
‘’’
#include
using namespace std;
#define ll long long int
int main() {
// your code goes here
ll t;
cin>>t;
while(t–){
ll n,m;
cin>>n>>m;
ll arr[n+1][m+1];
for (ll i=0;i<=n;i++) {
for(ll j=0;j<=m;j++){
if(i==0 || j==0)
arr[i][j]=0;
else
cin>>arr[i][j];
}
}
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
arr[i][j]+=arr[i-1][j]+arr[i][j-1]-arr[i-1][j-1];
}
}
ll q;
cin>>q;
while(q--){
int a,b,x,y;
cin>>a>>b>>x>>y;
ll ans=0;
ans=arr[x][y]-arr[a-1][y]-arr[x][b-1]+arr[a-1][b-1];
cout<<ans<<endl;
}
}
return 0;
}
‘’’
also, I checked some successful submission and they did the same as what I am doing
but still, I am getting TLE can someone please help me??