合并果子
用优先队列一直取出最小的就好
#include
<bits
/stdc
++.h
>
using namespace std
;
priority_queue
<int,vector
<int>,greater
<int> >p
;
int main(){
int n
,t
,ans
=0;
cin
>>n
;
for(int i
=0;i
<n
;i
++){
cin
>>t
;
p
.push(t
);
}
int f
=0,cnt
=1;
while(!p
.empty()){
if(cnt
&1){
f
=p
.top();
p
.pop();
}else {
f
+=p
.top();
p
.pop();
ans
+=f
;
p
.push(f
);
}
cnt
++;
}
cout
<<ans
;
return 0;
}
明天再写树的差分。。。 今天水了
转载请注明原文地址: https://win8.8miu.com/read-18627.html