diff --git a/Codeforces/13/C/C.cpp b/Codeforces/13/C/C.cpp new file mode 100644 index 00000000..1be37a77 --- /dev/null +++ b/Codeforces/13/C/C.cpp @@ -0,0 +1,35 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e6 + 5; + +int n; +long long ans; +std::priority_queue 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; +}