diff options
author | Ta180m | 2020-01-14 14:07:34 -0600 |
---|---|---|
committer | GitHub | 2020-01-14 14:07:34 -0600 |
commit | 8171be7a98941ee855fed7bc758d139f5a02dec1 (patch) | |
tree | b29a877456733f2eb8028881ecdd32f21793e4aa | |
parent | b3a80bbc40fd5173128c69da71ba97558eb0f1a1 (diff) |
Create restack.cpp
-rw-r--r-- | 2012/March/Gold/restack.cpp | 16 |
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'; +} |