提交时间:2024-04-10 13:41:44
运行 ID: 142851
#include<bits/stdc++.h> using namespace std; const int N=50000+100,INF=0x3f3f3f3f; int n,a[N],b[N],d[N]; bool cmp(int x,int y){ return x>y; } int main(){ while(1){ cin>>n; if(n==0)break; int c,maxx,minn; for(int i=1;i<=n;i++){ cin>>a[i]; b[i]=a[i]; } c=n; while(c!=1){ sort(b+1,b+c+1); b[1]=b[1]*b[2]+1; for(int i=3;i<=c;i++)b[i-1]=b[i]; c--; } maxx=b[1]; c=n; while(c!=1){ sort(a+1,a+c+1,cmp); a[1]=a[1]*a[2]+1; for(int i=2;i<c;i++)a[i]=a[i+1]; c--; } minn=a[1]; cout<<maxx-minn<<endl; } return 0; }