提交时间:2024-03-02 09:01:56
运行 ID: 133751
#include <bits/stdc++.h> using namespace std; priority_queue <int, vector <int>, greater <int> > q1; priority_queue <int> q2; int main() { int n; cin >> n; 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(); int tmp3 = tmp1 * tmp2 + 1; q1.push(tmp3); } while (q2.size() != 1) { int tmp1 = q2.top(); q2.pop(); int tmp2 = q2.top(); q2.pop(); int tmp3 = tmp1 * tmp2 + 1; q2.push(tmp3); } cout << q1.top() - q2.top() << endl; }