提交时间:2023-12-12 16:13:29
运行 ID: 115626
#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; }