Submission #527759

# Submission time Handle Problem Language Result Execution time Memory
527759 2022-02-18T08:09:11 Z KoD Autobahn (COI21_autobahn) C++17
100 / 100
120 ms 7856 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

int lowb(const std::vector<int>& v, const int x) {
    return std::lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, K, X;
    std::cin >> N >> K >> X;
    vector<int> L(N), T(N), R(N), cx;
    for (int i = 0; i < N; ++i) {
        std::cin >> L[i] >> T[i] >> R[i];
        R[i] += 1;
        cx.push_back(L[i]);
        cx.push_back(L[i] + T[i]);
        cx.push_back(R[i]);
    }
    std::sort(cx.begin(), cx.end());
    cx.erase(std::unique(cx.begin(), cx.end()), cx.end());
    const int n = cx.size();
    vector<int> exist(n), coeff(n);
    for (int i = 0; i < N; ++i) {
        exist[std::lower_bound(cx.begin(), cx.end(), L[i]) - cx.begin()] += 1;
        exist[std::lower_bound(cx.begin(), cx.end(), R[i]) - cx.begin()] -= 1;
        if (L[i] + T[i] < R[i]) {
            coeff[std::lower_bound(cx.begin(), cx.end(), L[i] + T[i]) - cx.begin()] += 1;
            coeff[std::lower_bound(cx.begin(), cx.end(), R[i]) - cx.begin()] -= 1;
        }
    }
    for (int i = 1; i < n; ++i) {
        exist[i] += exist[i - 1];
        coeff[i] += coeff[i - 1];
    }
    for (int i = 0; i < n; ++i) {
        if (exist[i] < K) {
            coeff[i] = 0;
        }
    }
    long long sum = 0, ans = 0;
    for (int i = 0, j = 0; i < n; ++i) {
        while (j + 1 < n and cx[j + 1] - cx[i] <= X) {
            sum += (long long) (cx[j + 1] - cx[j]) * coeff[j];
            j += 1;
        }
        ans = std::max(ans, sum + (long long) coeff[j] * (X - (cx[j] - cx[i])));
        if (i == j) {
            j += 1;
        } else {
            sum -= (long long) (cx[i + 1] - cx[i]) * coeff[i];
        }
    }
    for (int i = n - 1, j = n - 1; i >= 0; --i) {
        while (j > 0 and cx[i] - cx[j - 1] <= X) {
            sum += (long long)(cx[j] - cx[j - 1]) * coeff[j - 1];
            j -= 1;
        }
        ans = std::max(ans, sum + (long long)(j == 0 ? 0 : coeff[j - 1]) * (X - (cx[i] - cx[j])));
        if (i == j) {
            j -= 1;
        } else {
            sum -= (long long) (cx[i] - cx[i - 1]) * coeff[i - 1];
        }
    }
    std::cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 104 ms 5064 KB Output is correct
22 Correct 106 ms 5100 KB Output is correct
23 Correct 105 ms 5100 KB Output is correct
24 Correct 111 ms 5128 KB Output is correct
25 Correct 120 ms 5096 KB Output is correct
26 Correct 112 ms 7836 KB Output is correct
27 Correct 102 ms 7856 KB Output is correct
28 Correct 119 ms 7856 KB Output is correct
29 Correct 110 ms 7740 KB Output is correct