Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
377870 | 1223333333 | 提高:贪心:数列极差 | C++ | 通过 | 100 | 0 MS | 272 KB | 760 | 2025-02-23 10:27:29 |
#include <bits/stdc++.h> using namespace std; int n; priority_queue<int,vector<int>,greater<int> >a;//小跟堆 priority_queue<int>b; int sumb; int sums; int ans; int main() { scanf("%d",&n); for(int i=1; i<=n; i++) { int m; scanf("%d",&m); a.push(m); b.push(m); } if(n==2) { printf("0\n"); return 0; } if(n==3) { printf("%lld",b.top()-a.top()); return 0; } while(!a.empty()) { int u=a.top(); a.pop(); int v=a.top(); a.pop(); int s=u*v+1; if(!a.empty()) a.push(s); else sumb=s; } while(!b.empty()) { int u=b.top(); b.pop(); int v=b.top(); b.pop(); int s=u*v+1; if(!b.empty()) b.push(s); else sums=s; } ans=sumb-sums; printf("%d",ans); return 0; }