#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 |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |