提交时间:2023-11-04 11:18:09

运行 ID: 108860

#include<bits/stdc++.h> using namespace std; const int N=50000+100; const int INF=0x3f3f3f3f; int n,a[N],maxx,minn,b[N]; bool cmp(int x,int y) { return x>y; } int main() { while(1) { cin>>n; if(n==0) { break; } int c=n,maxx,minn; for(int i=1;i<=n;i++) { cin>>a[i]; b[i]=a[i]; } while(c!=1) { sort(b+1,b+c+1); b[1]=b[1]*b[2]+1; for(int i=2;i<c;i++) { b[i]=b[i+1]; } 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=c;i>2;i--) { a[i-1]=a[i]; } c--; } minn=a[1]; cout<<maxx-minn<<endl; } return 0; }