0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 01:48:56 +00:00

P4597 序列 sequence

https://www.luogu.com.cn/record/99038877
This commit is contained in:
Baoshuo Ren 2023-01-08 16:53:34 +08:00
parent a9e7e67b77
commit 4706bdfdc4
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

35
Luogu/P4597/P4597.cpp Normal file
View 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;
}