mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 15:18:46 +00:00
parent
4706bdfdc4
commit
1bbe5af4cb
35
Codeforces/13/C/C.cpp
Normal file
35
Codeforces/13/C/C.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e6 + 5;
|
||||
|
||||
int n;
|
||||
long long ans;
|
||||
std::priority_queue<long long> q;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1, x; i <= n; i++) {
|
||||
cin >> x;
|
||||
|
||||
q.emplace(x);
|
||||
|
||||
if (x < q.top()) {
|
||||
ans += q.top() - x;
|
||||
q.pop();
|
||||
q.emplace(x);
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user