Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
134673 林泽豪 紧急集合 C++ 通过 100 3 MS 292 KB 763 2024-03-02 16:54:36

Tests(10/10):


#include<bits/stdc++.h> using namespace std ; const int maxn=114514; int heap[maxn],heap_size=0; void put (int d){ int now,next ; heap[++heap_size]=d; now=heap_size; while(now>1) { next=now>>1; if(heap[now]>=heap[next])break; swap(heap[now],heap[next]); now=next; } } int get(){ int now=1,next ,res=heap[1]; heap[1]=heap[heap_size--]; while(now*2<=heap_size){ next=now*2; if(next<heap_size&&heap[next+1]<heap[next])next++; if(heap[now]<=heap[next])break; swap(heap[now],heap[next]); now=next; } return res; } int main(){; int n,fruit=0; cin>>n; for(int i=1;i<=n;i++){ int p; cin>>p; put(p); } while(heap_size!=1){ int su=get()+get(); put(su); fruit+=su; } cout<<fruit; }


测评信息: