Hey anyone can tell me what is difference between these two code 1st is giving AC and second one is WA but according to me both are same plz help.
AC one
//HEADERS
int Mat[1025][1025];
int dp[1025][1025];
int main()
{
int T;
scanf("%d", &T);
int t = 1;
while(T--) {
int d;
memset(Mat, 0, sizeof Mat);
memset(dp, 0, sizeof dp);
int N;
scanf("%d", &d);
scanf("%d", &N);
int x[N + 2];
int y[N + 2];
for(int i = 0; i < N; ++i) {
int p;
scanf("%d%d%d", &x[i], &y[i], &p);
Mat[x[i]][y[i]] += p;
for(int j = max(x[i] - d, 0); j <= min(x[i] + d, 1024); ++j) {
for(int k = max(y[i] - d, 0); k <= min(y[i] + d, 1024); ++k) {
dp[j][k] += Mat[x[i]][y[i]];
}
}
}
int cnt = 0;
int X = 0;
int Y = 0;
for(int i = 0; i <= 1024; ++i) {
for(int j = 0; j <= 1024; ++j) {
if(dp[i][j] > cnt) {
cnt = dp[i][j];
X = i;
Y = j;
}
}
}
printf("%d %d %d\n", X, Y, cnt);
}
return 0;
}
WA
//Headers
int Mat[1025][1025];
int dp[1025][1025];
int main()
{
int T;
scanf("%d", &T);
int t = 1;
while(T--) {
int d;
memset(Mat, 0, sizeof Mat);
memset(dp, 0, sizeof dp);
int N;
scanf("%d", &d);
scanf("%d", &N);
int x[N + 2];
int y[N + 2];
for(int i = 0; i < N; ++i) {
int p;
scanf("%d%d%d", &x[i], &y[i], &p);
Mat[x[i]][y[i]] += p;
}
for(int i = 0; i < N; ++i) {
for(int j = max(x[i] - d, 0); j <= min(x[i] + d, 1024); ++j) {
for(int k = max(y[i] - d, 0); k <= min(y[i] + d, 1024); ++k) {
dp[j][k] += Mat[x[i]][y[i]];
}
}
}
int cnt = 0;
int X = 0;
int Y = 0;
for(int i = 0; i <= 1024; ++i) {
for(int j = 0; j <= 1024; ++j) {
if(dp[i][j] > cnt) {
cnt = dp[i][j];
X = i;
Y = j;
}
}
}
printf("%d %d %d\n", X, Y, cnt);
}
return 0;
}