标签:更新 while sum return ++ inline n+1 ret space
#include<bits/stdc++.h>
#define R register int
#define ll long long
using namespace std;
const int N=100001;
int n,w[N],res[N],le,ri,z,y;ll ans;
int gi(){
R x=0,k=1;char c=getchar();
while(c!=‘-‘&&(c<‘0‘||c>‘9‘))c=getchar();
if(c==‘-‘)k=-1,c=getchar();
while(c>=‘0‘&&c<=‘9‘)x=(x<<3)+(x<<1)+c-‘0‘,c=getchar();
return x*k;
}
int main(){
n=gi();
for(R i=1;i<=n;++i)w[i]=gi();
sort(w+1,w+n+1);
le=2,ri=n,z=w[1],y=w[1];
while(le<=ri){
R p=abs(w[le]-z),q=abs(w[le]-y),a=abs(w[ri]-z),b=abs(w[ri]-y),Mx=max(max(p,q),max(a,b));
if(Mx==p)z=w[le],le++;
else if(Mx==q)y=w[le],le++;
else if(Mx==a)z=w[ri],ri--;
else y=w[ri],ri--;
ans+=Mx;
}
cout<<ans<<endl;
return 0;
}
Tenka1 Programmer Contest C - Align
标签:更新 while sum return ++ inline n+1 ret space
原文地址:https://www.cnblogs.com/Tyher/p/9863504.html