This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
#define int long long
const int N = (int)1e5+10;
int n;
vector<int> v[N];
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n; int ans = 0;
for(int i = 0; i < 2*n; i++){
int x, y; cin >> x >> y;
v[1].pb(x), v[0].pb(y);
}
for(int j : {0,1}) sort(all(v[j]));
int x = 1;
for(int i = 0; i < 2*n; i++){
if(i<n) ans+=abs(v[0][i])+abs(x-v[1][i]);
else ans+=abs(v[0][i]-1)+abs(x-v[1][i]);
if(i%2) x++;
}
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... |