제출 #127339

#제출 시각아이디문제언어결과실행 시간메모리
127339wasylCoin Collecting (JOI19_ho_t4)C++11
100 / 100
67 ms4972 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...