提交时间:2023-11-02 13:33:53
运行 ID: 108358
//I am Block Xuan #include<bits/stdc++.h> //I am Block Xuan #define int long long //I am Block Xuan using namespace std; //I am Block Xuan int a[50005]; //I am Block Xuan //I am Block Xuan signed main(){ //I am Block Xuan int n; //I am Block Xuan while (cin>>n){ //I am Block Xuan if (n == 0){ //I am Block Xuan break; //I am Block Xuan } //I am Block Xuan priority_queue <int> p; //I am Block Xuan priority_queue <int,vector <int>,greater <int> > q; //I am Block Xuan for (int i = 1;i <= n;i++){ //I am Block Xuan cin>>a[i]; //I am Block Xuan p.push(a[i]); //I am Block Xuan q.push(a[i]); //I am Block Xuan } //I am Block Xuan while (p.size() >= 2){ //I am Block Xuan int a = p.top(); //I am Block Xuan p.pop(); //I am Block Xuan int b = p.top(); //I am Block Xuan p.pop(); //I am Block Xuan p.push(a * b + 1); //I am Block Xuan } //I am Block Xuan while (q.size() >= 2){ //I am Block Xuan int a = q.top(); //I am Block Xuan q.pop(); //I am Block Xuan int b = q.top(); //I am Block Xuan q.pop(); //I am Block Xuan q.push(a * b + 1); //I am Block Xuan } //I am Block Xuan cout<<q.top() - p.top()<<'\n'; //I am Block Xuan } //I am Block Xuan return 0; //I am Block Xuan } //I am Block Xuan