This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//çalışan kazanır//
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0)
int gcd (int a, int b) {if (b == 0){return a;}else {return gcd (b, a % b);}}
const int N = 4e5 + 15;
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int MODD = 1070234587ll;
const double eps = 0.0001;
const int p = 87;
int n;// x[N], y[N], u[3];
int dp[2001][2001], cnt[N][3];
pair <int, int> x[N];
void solution () {
cin >> n;
for (int i = 1; i <= n * 2; ++ i) cin >> x[i].F >> x[i].S;
int res = 0;
sort (x + 1, x + n + n + 1);
for (int i = 0; i < n * 2; ++ i) {
res += abs(x[i + 1].F - (i / 2 + 1));
if (i % 2) {
int w = abs(x[i + 1].S - 2) + abs(x[i].S - 1);
w = min (w, abs(x[i].S - 2) + abs(x[i + 1].S - 1));
res += w;
// cout << i << " => " << w << '\n';
}
}
cout << res;
return;
}
signed main() {
YOSIK();
srand (time(0));
// freopen ("E.in", "r", stdin);
// freopen ("E.out", "w", stdout);
int TT = 1;// cin >> TT;
for (int i = 1; i <= TT; ++ i) {
// cout << "Case " << i << ": ";
solution ();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |