Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
136526 mairuisheng 紧急集合 C++ 通过 100 2 MS 292 KB 961 2024-03-09 10:08:40

Tests(10/10):


#include<bits/stdc++.h> using namespace std; int n,guo,heap_size,ans=0,ans1=0,x,y; int heap[10001]; 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; else swap(heap[now],heap[next]); now=next; } } int get() { int now,next,res; res=heap[1]; heap[1]=heap[heap_size--]; now=1; while(now*2<=heap_size) { next=now*2; if(next<heap_size&&heap[next+1]<heap[next]) next++; if(heap[now]>heap[next]) swap(heap[now],heap[next]); now=next; } return res; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&guo); put(guo); } for(int i=1;i<n ;i++) { x=get(); y=get(); ans+=x+y; put(x+y); } cout<<ans; return 0; }


测评信息: