Help me in solving LARGESECOND problem

My issue

i am not able to solve

My code

#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int N;
        cin>>N;
        int A[N];
        for(int i=0;i<N;i++){
            cin>>A[i];
        }int max=A[0];
         
            for(int j=1;j<N;j++){
                if(max>A[j])
                max= max;
                else
                max=A[j];
            }
            // int secmax;
            // secmax=A[0];
            // for(int i=1;i<N;i++){
            //     if(secmax<max){
                     
            //     }
            // }
        
    }cout<<max<<'\n';
	// your code goes here
	return 0;
}

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

@techno_628
refer the following code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    int mx1=0,mx2=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        mx1=max(mx1,a[i]);
	    }
	    for(int i=0;i<n;i++)
	    {
	        if(a[i]!=mx1)
	        mx2=max(mx2,a[i]);
	    }
	    cout<<mx1+mx2<<endl;
	}
	return 0;
}