提交时间:2023-11-04 12:41:25
运行 ID: 108913
#include<bits/stdc++.h> using namespace std; const int N=50000+100; const int 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]; } cout<<endl; 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--; cout<<endl; } minn=a[1]; cout<<maxx-minn<<endl; } return 0; }