提交时间:2023-11-01 13:59:12

运行 ID: 108268

#include<bits/stdc++.h> #define int long long using namespace std; int a[50005]; signed main(){ int n; while (cin>>n){ if (n == 0){ break; } priority_queue <int> p; priority_queue <int,vector <int>,greater <int> > q; for (int i = 1;i <= n;i++){ cin>>a[i]; p.push(a[i]); q.push(a[i]); } while (p.size() >= 2){ int a = p.top(); p.pop(); int b = p.top(); p.pop(); p.push(a * b + 1); } while (q.size() >= 2){ int a = q.top(); q.pop(); int b = q.top(); q.pop(); q.push(a * b + 1); } cout<<q.top() - p.top()<<'\n'; } return 0; }