0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:25:24 +00:00

P3076 [USACO13FEB]Taxi G

https://www.luogu.com.cn/record/85669174
This commit is contained in:
Baoshuo Ren 2022-09-02 09:26:40 +08:00
parent b07ef359ca
commit bacfa27ddb
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

38
Luogu/P3076/P3076.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <iostream>
#include <algorithm>
#include <cmath>
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;
}