WA in SMPAIR

p: https://onlinegdb.com/SJyEOpFJ8
q :https://www.codechef.com/problems/SMPAIR
why it is wrong??

1 Like

here i, j need not be adjacent

Moreover your code accepts values for i==j

for(j=0;j<n;j++)
{
       for(k=1;k<n;k++)
       {
             A=a[j]+a[k];
             if(A<B)
             {
                 B=A;
             }
      }
}

Here, you are also considering the pair when i = j,
whereas the questions asks this,

1 ≤ i < jN

Replace k=j to k=j+1 but then again ur code will get TLE for some case since its N^2