提交时间:2023-11-04 11:17:21
运行 ID: 108857
#include <bits/stdc++.h> using namespace std; priority_queue<int> mx; priority_queue<int,vector<int>,greater<int> > mn; int main(){ int n; cin>>n; while(n!=0){ for(int i = 0;i<n;i++){ int x; cin>>x; mx.push(x); mn.push(x); } while(mx.size()>1) { int tmp1 = mx.top(); mx.pop(); int tmp2 = mx.top(); mx.pop(); mx.push(tmp1*tmp2+1); } while(mn.size()>1){ int tmp1 = mn.top(); mn.pop(); int tmp2 = mn.top(); mn.pop(); mn.push(tmp1*tmp2+1); } cout<<mn.top()-mx.top()<<endl; mn.pop();mx.pop(); cin>>n; } return 0; }