I was trying to solve some ds question, all the things were fine algo wise but answer wise (wrong), then to debug, I put cout to check where mistake has been done when I put cout answer is correct , but without it the answer is wrong also, the different online compiler is showing the right answer
without cout and Is 1:7:4 (wrong ans) with it answer is 1:7:3 (correct ans) input is 2 9 1 0 1 1 0 1 1 1 1 0 0 0 1 0 1 0 0 1
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
int a,b;
int ans=0;
int ansij=INT_MAX;
cin>>n>>m;
int arr[n+10][m+10];
for(int i=0;i<n;i++)
{
{ for(int j=0;j<m;j++)
cin>>arr[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{ if(i==0&&j==0)
continue;
int score=0;
if(arr[i][j]==1)
{ //cout<<arr[i][j]<<endl ;
//1
if(arr[i+1][j]==1)
score++;
//2
if(arr[i][j+1]==1)
score++;
//3
if(arr[i-1][j]==1)
score++;
//4
if(arr[i][j-1]==1)
score++;
//5
if(arr[i+1][j+1]==1)
score++;
//6
if(arr[i+1][j-1]==1)
score++;
//7
if(arr[i-1][j+1]==1)
score++;
//8
if(arr[i-1][j-1]==1)
score++;
}
//cout<<"";
//cout<<"score of i and j is ("<<i+1<<","<<j+1<<") "<<score<<endl;
if(ans<score)
{ ans=score;
ansij=i+j;
a=i;
b=j;
//cout<<" answer update from gretest"<<endl;
}
else if(ans==score)
{ if(ansij>=(i+j))
{ ans=score;
ansij=i+j;
a=i;
b=j;
//cout<<" answer update from qual"<<endl;
}
}
//cout<<" answer in i j is"<<ans<<endl;
}
}
cout<<a+1<<":"<<b+1<<":"<<ans;
return 0;
}