#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, x[200200], y[200200], c[100100][2];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1;i<=n+n;i++) cin >> x[i] >> y[i];
ll ans = 0;
for(int i=1;i<=n+n;i++) {
int D = min(max(x[i], 1), n);
ans += abs(D-x[i]);
if(y[i] >= 2) {
c[D][0]++;
ans += y[i]-2;
} else {
c[D][1]++;
ans += 1-y[i];
}
}
for(int i=1;i<=n;i++) {
c[i][0] += c[i-1][0]-1;
c[i][1] += c[i-1][1]-1;
if(c[i][0] > 0 && c[i][1] < 0) c[i][0]--, c[i][1]++, ans++;
if(c[i][1] > 0 && c[i][0] < 0) c[i][1]--, c[i][0]++, ans++;
ans += abs(c[i][0]) + abs(c[i][1]);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2512 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2512 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2512 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |