code from link above
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("elicop.in");
ofstream out("elicop.out");
int m,n,k,a[2],b[2],sj,linie=1,nr,nru,cateta,punct[2],aux,auxx,i,j,c,l,nrelicop=0,cr;
in>>m>>n;
int teren[m+1][n+1];
for(aux=1; aux<=m; aux++)
{
for(auxx=1; auxx<=n; auxx++)
{
in>>teren[aux][auxx];
}
}
in>>k;
int prop[k][5];
for(aux=1; aux<=k; aux++)
{
for(auxx=1; auxx<=5; auxx++)
{
in>>prop[aux][auxx];
}
}
while(k!=0)
{
a[2]=prop[linie][2];
a[1]=prop[linie][1];
b[1]=prop[linie][3];
b[2]=prop[linie][4];
sj=prop[linie][5];
linie=linie+1;
if(sj==-1)
{
if(b[1]>a[1])
{
punct[1]=b[1];
punct[2]=a[2];
}
else
{
punct[1]=a[1];
punct[2]=b[2];
}
l=punct[1];
if(punct[1]-a[1]<0)
{
cateta=-(punct[1]-a[1]-1);
}
else
{
cateta=punct[1]-a[1]+1;
}
c=cateta;
nru=0;
nr=0;
while(l!=0)
{
for(i=1; i<=l; i++)
{
for(j=1; j<=c; j++)
{
cr=teren[i][j];
if(cr==0)
{
nru=nru+1;
}
nr=nr+1;
}
c=c-1;
}
l=l-1;
}
if(nru==nr)
{
nrelicop=nrelicop+1;
}
else
{
if(nru>nr/2)
{
out<<k<<" ";
}
else
{
nrelicop=nrelicop+1;
}
}
}
else
{
if(a[1]>b[1])
{
punct[1]=a[1];
punct[2]=b[2];
}
else
{
punct[1]=b[1];
punct[2]=a[2];
}
l=punct[1];
if(punct[1]-a[1]<0)
{
cateta=-(punct[1]-a[1]-1);
}
else
{
cateta=punct[1]-a[1]+1;
}
c=cateta;
nru=0;
nr=0;
while(l!=0)
{
for(i=1; i<=l; i++)
{
for(j=1; j<=c; j++)
{
cr=teren[i][j];
if(cr==0)
{
nru=nru+1;
}
nr=nr+1;
}
c=c-1;
}
l=l-1;
}
if(nru==nr)
{
nrelicop=nrelicop+1;
}
else
{
if(nru>nr/2)
{
out<<k<<" ";
}
else
{
nrelicop=nrelicop+1;
}
}
}
k=k-1;
}
out<<endl<<nrelicop;
return 0;
}
int m,n,k,a[2],b[2] ........;
while(k!=0)
{
a[2]=prop[linie][2];
How many items does a[] have?
It's because of how you declared
a[2]: which creates an array of 2 items: a[0] and a[1].
And then tried to access index 3, ie. a[2].
I don't know, and might depend on the compiler used, but your variables (in the order you declared them) will be laid out in ram in one of two ways:
from left-to-right, or right-to-left.

See how in the 2nd example (variables created in reverse order), a[2] would actually give the memory location of 'k'.
If you wrote to a[3] (index 4), I believe it would also over-write 'n'.
C++ doesn't have index-checking. That is, if you refer to a[10000], it will calculate the address where that item WOULD be, and continue as normal. It doesn't enforce the fact that you declared a[] to only have 2 items.
edit: int may not be 4 bytes on your platform..same concept still applies.