Help me in solving LARGESECOND problem

My issue

issue kay hai

My code

#include <iostream>
using namespace std;


 void swap( int &c,int &b){
    int temp;
     temp=c;
     c=b;
     b=temp;

 }

int main() {
    int sum=0;

      int t;
      cin>>t;
      while(t--){
          int n;
          cin>>n;
          int a[n];
          for(int i=0;i<n;i++){
              cin>>a[i];
          }
          for(int j=0;j<n;j++){
              
          for(int i=0;i<n-j-1;i++){
          if(a[i]>a[i+1]){
            swap(a[i],a[i+1]);
             
          }
          
          }
         
          }
         for(int i=n-1; i>0;i--){
              if(a[i]!=a[i-1]){
              sum=a[i]+a[i-1];
              break;
              }
          }
        
       
           
        
          cout<<sum<<endl;
      }
	return 0;
}

Learning course: Arrays using C++
Problem Link: Largest and Second Largest Practice Problem in - CodeChef

@anon26998785
due to high constraints O(n^2) complexity will give u tle.
use sort function to reduce.