Skip to content

Commit 85ce78d

Browse files
committed
Slope trick
1 parent 98ecb17 commit 85ce78d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <bits/stdc++.h>
2+
3+
int main() {
4+
int n;
5+
scanf("%d", &n);
6+
long long ans = 0;
7+
std::priority_queue<int> slope_change;
8+
while (n--) {
9+
int a;
10+
scanf("%d", &a);
11+
slope_change.push(a); slope_change.push(a);
12+
ans += slope_change.top() - a;
13+
slope_change.pop();
14+
}
15+
printf("%lld", ans);
16+
return 0;
17+
}

0 commit comments

Comments
 (0)