***额...额...额...***
by ZJH365 @ 2018-02-22 16:55:11
我复制交上去之后......AC。。。QAQ
by Scarlet_Lightning @ 2018-02-27 18:23:06
不存在RE
by Scarlet_Lightning @ 2018-02-27 18:23:26
你是从书上抄下来的
我知道
我也是
我只有10分
#include<iostream>
#include<cstdio>
using namespace std;
int heap_size,n;
int heap[30001];
void swap(int &a,int &b)
{
int t=a;
a=b;
b=t;
}
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])
return;
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++;
swap(heap[now],heap[next]);
now=next;
}
return res;
}
void work()
{
int i,x,y,z=0;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>x;
put(x);
}
for(i=1;i<n;i++)
{
x=get();
y=get();
z+=x+y;
put(x+y);
}
cout<<z<<endl;
}
int main()
{
ios::sync_with_stdio(false);
work();
return 0;
}1.- 1.
by 机智如狗 @ 2018-03-02 13:37:07