#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define INF 1e17
#define X first
#define Y second
vector<pair<ll, ll>> coin;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i = 0; i < 2*n; i++)
{
int x, y;
cin >> x >> y;
coin.push_back({x, y});
}
sort(coin.begin(), coin.end());
ll ans = 0;
for(int i = 0; i < 2*n; i += 2)
{
ans += (abs(i/2+1-coin[i].X)+abs(i/2+1-coin[i+1].X));
ans += min(abs(1-coin[i].Y)+abs(2-coin[i+1].Y), abs(1-coin[i+1].Y)+abs(2-coin[i].Y));
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |