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>
#define int long long
using namespace std;
const int nmax = 3e5 + 1;
int f[nmax][3];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, ans = 0;
cin >> n;
for(int i = 1; i <= 2 * n; i ++) {
int a, b;
cin >> a >> b;
//cout << i << " ";
// punem in cel mai apropiat loc
if(a < 1) {
//cout << "b mai mic ";
ans += 1 - a;
a = 1;
} else if(a > n) {
//cout << "b mai mare ";
ans += a - n;
a = n;
}
if(b < 1) {
//cout << "a mai mic ";
ans += 1 - b;
b = 1;
} else if(b > 2) {
//cout << "a mai mare ";
ans += b - 2;
b = 2;
}
//cout << endl;
f[a][b] ++;
}
int a = 0, b = 0;
for(int i = 1; i <= n; i ++){
a += f[i][1] - 1, b += f[i][2] - 1;
while(a > 0 && b < 0) {
a --;
b ++;
ans ++;
}
while(a < 0 && b > 0) {
a ++;
b --;
ans ++;
}
ans += abs(a) + abs(b);
}
cout << ans;
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... |