diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
| commit | 96254947699986c59f0dc63d69fd4b76bd3ed43e (patch) | |
| tree | 6c4dca945d7f7427c48be234d827fe4d33be02c5 /02_sorting_and_searching/stick_lengths_1074.cpp | |
| download | cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip | |
Initial commit
Diffstat (limited to '02_sorting_and_searching/stick_lengths_1074.cpp')
| -rw-r--r-- | 02_sorting_and_searching/stick_lengths_1074.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/02_sorting_and_searching/stick_lengths_1074.cpp b/02_sorting_and_searching/stick_lengths_1074.cpp new file mode 100644 index 0000000..e41a7d8 --- /dev/null +++ b/02_sorting_and_searching/stick_lengths_1074.cpp | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <iostream> | ||
| 3 | #include <vector> | ||
| 4 | |||
| 5 | int main() { | ||
| 6 | long long n; | ||
| 7 | std::cin >> n; | ||
| 8 | std::vector<long long> a(n); | ||
| 9 | for (long long i = 0; i < n; i++) | ||
| 10 | std::cin >> a[i]; | ||
| 11 | std::sort(a.begin(), a.end()); | ||
| 12 | long long s{0}, t{a[n/2]}; | ||
| 13 | for (auto x : a) | ||
| 14 | s += std::abs(x-t); | ||
| 15 | std::cout << s << "\n"; | ||
| 16 | } | ||
