From fb4c5d18ef757ec7c5d2e4204b0b1b662c9a8c52 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 8 Jan 2023 18:28:05 +0800 Subject: [PATCH] C - Sonya and Problem Wihtout a Legend https://codeforces.com/contest/713/submission/188408984 --- Codeforces/713/C/C.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Codeforces/713/C/C.cpp diff --git a/Codeforces/713/C/C.cpp b/Codeforces/713/C/C.cpp new file mode 100644 index 00000000..3031acb6 --- /dev/null +++ b/Codeforces/713/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 - i); + + if (q.top() > x - i) { + ans += q.top() - (x - i); + q.pop(); + q.emplace(x - i); + } + } + + cout << ans << endl; + + return 0; +}