提交时间:2024-03-02 08:47:14
运行 ID: 133633
#include <bits/stdc++.h> #define int long long using namespace std; priority_queue<int> q1; priority_queue<int,vector<int>,greater<int> > q2; signed main() { int n; cin >> n; while (n != 0) { for (int i = 1; i <= n; i++) { int x; cin >> x; q1.push(x); q2.push(x); } while (q1.size() >= 2) { int x = q1.top(); q1.pop(); int y = q1.top(); q1.pop(); q1.push(x * y + 1); } while (q2.size() >= 2) { int x = q2.top(); q2.pop(); int y = q2.top(); q2.pop(); q2.push(x * y + 1); } printf("%lld\n",q2.top() - q1.top()); cin >> n; } return 0; }