48372023-03-31 16:28:15Error42TV szolgáltatókcpp17Wrong answer 0/40116ms7120 KiB
#include <algorithm>
#include <climits>
#include <iostream>
#include <functional>
#include <vector>

using namespace std;

using ll = long long;

// lo, hi > 0
template <typename T>
int binary_first_true(T lo, T hi, function<bool(T const&)> const& pred) {
    hi--;

    while (lo < hi) {
        T const mid = (lo + hi) / 2;

        if (pred(mid))
            hi = mid;
        else
            lo = mid + 1;
    }

    return lo;
}

int main() {
    int n, k;
    cin >> n >> k;

    vector<int> s(n);
    vector<int> e(n);

    for (int i = 0; i < n; i++)
        cin >> s[i] >> e[i];

    sort(s.rbegin(), s.rend());
    sort(e.begin(), e.end());


    vector<ll> cost(n + 1);
    cost[0] = LLONG_MAX / 3;
    {
        ll cur = 0;
        ll inc = 0;
        int j = 0;
        for (int i = 1; i <= n + k - 1; i++) {
            while (j < n && e[j] < i) {
                inc++;
                j++;
            }

            cur += inc;
            if (i - k + 1 > 0)
                cost[i - k + 1] += cur;
        }
    }
    {
        ll cur = 0;
        ll inc = 0;
        int j = 0;
        for (int i = n; i > 0; i--) {
            while (j < n && s[j] > i) {
                inc++;
                j++;
            }

            cur += inc;
            cost[i] += cur;
        }
    }

    cout << *min_element(cost.begin(), cost.end()) << "\n";
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Accepted0/03ms1808 KiB
2Wrong answer0/03ms2060 KiB
3Wrong answer0/13ms2272 KiB
4Wrong answer0/13ms2384 KiB
5Wrong answer0/13ms2536 KiB
6Wrong answer0/13ms2628 KiB
7Wrong answer0/23ms2620 KiB
8Wrong answer0/23ms2624 KiB
9Wrong answer0/23ms2752 KiB
10Wrong answer0/23ms2960 KiB
11Wrong answer0/246ms4304 KiB
12Wrong answer0/246ms4412 KiB
13Wrong answer0/246ms4388 KiB
14Wrong answer0/246ms4512 KiB
15Wrong answer0/292ms6412 KiB
16Wrong answer0/290ms6372 KiB
17Wrong answer0/256ms4872 KiB
18Wrong answer0/256ms4876 KiB
19Wrong answer0/256ms4940 KiB
20Wrong answer0/256ms5020 KiB
21Wrong answer0/156ms5112 KiB
22Wrong answer0/156ms5024 KiB
23Wrong answer0/1109ms6732 KiB
24Wrong answer0/1109ms7032 KiB
25Wrong answer0/1111ms7120 KiB
26Wrong answer0/1111ms6976 KiB
27Wrong answer0/1116ms6932 KiB
28Wrong answer0/1111ms6932 KiB