提交时间:2024-03-02 09:10:36

运行 ID: 133765

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