The Bookshelves Problem ZCO

This is my code :

#include
#include
using namespace std;
int main()
{
int n,k,in,j=0,skew,skew1,skew2;
cin>>n;
cin>>k;
long s1[n],s2[n],s3[n],s4[n],x;
for(int i=0;i<(n);i++)
{
cin>>s1[i];
s3[i]=s1[i];
}
for(int i=0;i<(n);i++)
{
cin>>s2[i];
s4[i]=s2[i];
}
for(int t=0;t<k;t++)
{
sort(s1, s1+n);
sort(s2, s2+n);
sort(s4, s4+n);
sort(s3, s3+n);

    x=s2[n-1];
    s2[n-1]=s1[0];
    s1[0]=x;
    sort(s1, s1+n);
    sort(s2, s2+n);
    skew1=s1[n-1]+s2[n-1];


    x=s3[n-1];
    s3[n-1]=s4[0];
    s4[0]=x;
    sort(s4, s4+n);
    sort(s3, s3+n);
    skew2=s3[n-1]+s4[n-1];
}
if(skew2>skew1) cout<<skew1;
if(skew2<skew1) cout<<skew2;
return 0;

}

I tried this for a few programs and it works completely fine but still it fails in subtask 2 when I submit the answer

//