aboutsummaryrefslogtreecommitdiff
path: root/12/mar/gold/restack.cpp
diff options
context:
space:
mode:
Diffstat (limited to '12/mar/gold/restack.cpp')
-rw-r--r--12/mar/gold/restack.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/12/mar/gold/restack.cpp b/12/mar/gold/restack.cpp
new file mode 100644
index 0000000..49b325d
--- /dev/null
+++ b/12/mar/gold/restack.cpp
@@ -0,0 +1,16 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+int main() {
+ ifstream cin("restack.in");
+ ofstream cout("restack.out");
+ int n, c = 0, ans = 0; cin >> n;
+ vector<int> v;
+ for (int i = 0; i < n; i++) {
+ int a, b; cin >> a >> b;
+ v.push_back(c += a - b);
+ }
+ sort(v.begin(), v.end());
+ for (int i = 0; i < n; i++) ans += abs(v[i] - v[n / 2]);
+ cout << ans << '\n';
+}