diff options
-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'; +} |