goj
啊!!
orzGEOTCBRL114514 STO_ORZ
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, ans, k;
priority_queue<int> q;
signed main() {
cin>>n;
for (int i = 1; i <= n; ++i) {
cin>>k;
if (!q.empty() && -q.top() < k) ans += k + q.top(), q.pop(), q.push(-k);
q.push(-k);
}
cout<<ans;
return 0;
}JSESSIONID=30BEBE2020CE77D99ED2BBAF2107D232