aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2020-01-14 14:07:34 -0600
committerGitHub2020-01-14 14:07:34 -0600
commit8171be7a98941ee855fed7bc758d139f5a02dec1 (patch)
treeb29a877456733f2eb8028881ecdd32f21793e4aa
parentb3a80bbc40fd5173128c69da71ba97558eb0f1a1 (diff)
Create restack.cpp
-rw-r--r--2012/March/Gold/restack.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/2012/March/Gold/restack.cpp b/2012/March/Gold/restack.cpp
new file mode 100644
index 0000000..49b325d
--- /dev/null
+++ b/2012/March/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';
+}