提交时间:2024-03-25 21:13:33

运行 ID: 139795

#include<bits/stdc++.h> using namespace std; int n; priority_queue<int> q1; priority_queue<int,vector<int>,greater<int> > q2; int t; int main() { while(cin>>n) { if(!n) { return 0; } while(!q1.empty()) { q1.pop(); q2.pop(); } for(int i=1;i<=n;i++) { cin>>t; q1.push(t); q2.push(t); } while(q1.size()!=1) { t=q1.top(); q1.pop(); t*=q1.top(); t++; q1.pop(); q1.push(t); } while(q2.size()!=1) { t=q2.top(); q2.pop(); t*=q2.top(); t++; q2.pop(); q2.push(t); } cout<<abs(q1.top()-q2.top()); cout<<endl; } return 0; }