#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n;
long long ans, cnt;
long long X[MAXN], Y[MAXN];
vector <long long> V;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= 2 * n; i++)
{
cin >> X[i] >> Y[i];
if(X[i] <= 0)
{
ans += (1 - X[i]);
X[i] = 1;
}
if(X[i] > n)
{
ans += (X[i] - n);
X[i] = n;
}
if(X[i] >= 1 and X[i] <= n)
{
if(Y[i] <= 1)
{
ans -= (Y[i] - 1);
cnt++;
}
else
{
ans += (Y[i] - 2);
}
V.push_back(X[i]);
}
}
sort(V.begin(), V.end());
ans += abs(cnt - n);
for(int i = 0; i < (int)V.size(); i += 2)
{
ans += abs(V[i] - i / 2 - 1);
ans += abs(V[i + 1] - i / 2 - 1);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |