From bacfa27ddb4c32b6727428b13c6d28f462ecb9ee Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 2 Sep 2022 09:26:40 +0800 Subject: [PATCH] P3076 [USACO13FEB]Taxi G https://www.luogu.com.cn/record/85669174 --- Luogu/P3076/P3076.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Luogu/P3076/P3076.cpp diff --git a/Luogu/P3076/P3076.cpp b/Luogu/P3076/P3076.cpp new file mode 100644 index 00000000..4072290e --- /dev/null +++ b/Luogu/P3076/P3076.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, m, x[N], y[N]; +long long ans; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + x[0] = m; + + for (int i = 1; i <= n; i++) { + cin >> x[i] >> y[i]; + + ans += std::abs(x[i] - y[i]); + } + + std::sort(x, x + 1 + n); + std::sort(y, y + 1 + n); + + for (int i = 0; i <= n; i++) { + ans += std::abs(x[i] - y[i]); + } + + cout << ans << endl; + + return 0; +}