Error The Smallest Pair Problem Code: SMPAIR

hey i get the result as wrong answer in codechef for my code but while executing the code in my compiler it runs good and gives correct answer

#include <iostream>
using namespace std;

int main() {int t,n,a[10],sum,j,i,temp=1000; cin>>t; while(t--) {
cin>>n; 
for(i=0;i<n;i++)
 {cin="">>a[i]; } 
for(i=0;i<n;i++)
 { 
for(j=i+1;j<n;j++)
 { sum=a[i]+a[j]; 
if(sum<temp) 
temp=sum;

}
} cout<<temp<<endl;

} return 0; }

whats wrong i it?

This is wrong-

temp=1000; 

a[i] and a[j] can be as large as 10^6 . Your code will fail for cases where array elements are more than 1000.

Say-

Array is {1001,2000,3000}

Least sum is 3001, but you will print 1000 due to temp variable’s initialisation