#include <cstdio>
#include <algorithm>
using namespace std;
int a[200005]={};
int main()
{
int n,s;
scanf("%d %d",&n,&s);
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
long long np=s;
int li=0;
int ri=n-1;
for(int k=0; k<n; k++)
{
if(n%2==0)
{
if(k%2==0)
{
np=2*a[li]-np;
li++;
}
else
{
np=2*a[ri]-np;
ri--;
}
}
else
{
if(k%2==0)
{
np=2*a[ri]-np;
ri--;
}
else
{
np=2*a[li]-np;
li++;
}
}
}
printf("%lld",np);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: