From 8171be7a98941ee855fed7bc758d139f5a02dec1 Mon Sep 17 00:00:00 2001 From: Ta180m Date: Tue, 14 Jan 2020 14:07:34 -0600 Subject: Create restack.cpp --- 2012/March/Gold/restack.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2012/March/Gold/restack.cpp 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 +using namespace std; + +int main() { + ifstream cin("restack.in"); + ofstream cout("restack.out"); + int n, c = 0, ans = 0; cin >> n; + vector 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'; +} -- cgit v1.2.3-70-g09d2