题解
2024-03-19 20:31:33
发布于:陕西
4阅读
0回复
0点赞
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
#define null liuyifan_null
#define y1 liuyifan_y1
#define next liuyifan_next
#define data liuyifan_data
using namespace std;
priority_queue<ll>q;//默认为大根堆
ll n,x,ans;
int main()
{
scanf("%lld",&n);
for(reg int i=1;i<=n;i++)
{
scanf("%lld",&x);
q.push(x);//插入堆
if(q.top()>x)
{
ans+=q.top()-x;//top:堆顶的值
q.pop();//弹出堆顶
q.push(x);
}
}
printf("%lld",ans);
return 0;
}
这里空空如也
有帮助,赞一个