This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> pii;
int main(){
int n;
cin >> n;
priority_queue<pii> fila;
long long ans=0;
for(int i=1; i<=2*n; i++){
pii atual;
cin >> atual.first >> atual.second;
fila.push(atual);
}
for(int i=n; i>=1; i--){
pii atual1 = fila.top();
fila.pop();
pii atual2 = fila.top();
fila.pop();
long long dist1 = abs(atual1.first-i) + abs(atual1.second-1);
dist1 += abs(atual2.first-i) + abs(atual2.second-2);
long long dist2 = abs(atual2.first-i) + abs(atual2.second-1);
dist2 += abs(atual1.first-i) + abs(atual1.second-2);
ans+=min(dist1, dist2);
}
cout << ans << endl;
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... |