Run ID Author Problem Lang Verdict Score Time Memory Code Length Submit Time
227798 陆沛埦 提高:贪心:数列极差 C++ Accepted 100 0 MS 264 KB 760 2023-12-31 13:52:01

Tests(2/2):


#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; }


Judgement Protocol: