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;
using ll = long long;
constexpr int nax = 1e5;
int n, cnt[nax + 1][2], bil[2]; ll res;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= 2 * n; ++i)
{
int x, y; cin >> x >> y;
res += max(0, x - n);
res += max(0, 1 - x);
res += max(0, y - 2);
res += max(0, 1 - y);
x = min(x, n);
x = max(x, 1);
y = min(y, 2);
y = max(y, 1);
++cnt[x][y - 1];
}
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j < 2; ++j)
bil[j] += cnt[i][j], --bil[j];
for (int j = 0; j < 2; ++j)
if (bil[j] > 0 and bil[1 - j] < 0)
{
int q = min(-bil[1 - j], bil[j]);
res += q;
bil[j] -= q;
bil[1 - j] += q;
}
for (int j = 0; j < 2; ++j)
res += abs(bil[j]);
}
cout << res << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |