大小差肯定只能是大小堆 #include<bits/stdc++.h> using namespace std; int main() { int N; cin >> N; priority_queue<int>bigheap; priority_queue<int, vector<int>, greater<int>> smallheap; for (int i = 0; i < N; i++) { int tem; cin >> tem; bigheap.push(tem); smallheap.push(tem); } while (bigheap.size() != 1) { int a = bigheap.top(); bigheap.pop(); int b = bigheap.top(); bigheap.pop(); bigheap.push(a * b + 1); } int min = bigheap.top(); while (smallheap.size() != 1) { int a = smallheap.top(); smallheap.pop(); int b = smallheap.top(); smallheap.pop(); smallheap.push(a * b + 1); } int max = smallheap.top(); cout << max - min<<endl; return 0; }
点赞 评论

相关推荐

点赞 评论 收藏
分享
吴offer选手:下午mt一来就告警说项目来不及,估计明天拿了权限就要参与开发了 已老实
实习生的蛐蛐区
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务