Submission #997904

# Submission time Handle Problem Language Result Execution time Memory
997904 2024-06-13T06:19:09 Z piOOE Autobahn (COI21_autobahn) C++17
100 / 100
57 ms 12808 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k, x;
    cin >> n >> k >> x;

    vector<pair<int, int>> events;
    for (int i = 0; i < n; ++i) {
        int l, r, t;
        cin >> l >> t >> r;
        r += 1;
        events.push_back({l, -1});
        events.push_back({r, 1});
        events.push_back({min(r, l + t), 0});
    }
    sort(events.begin(), events.end());

    int alive = 0, pay = 0, lastx = -1;
    vector<int> a, c;
    for (auto [dx, t] : events) {
        if (lastx != dx) {
            if (lastx != -1) {
                a.push_back(lastx);
                c.push_back(alive >= k ? pay : 0);
            }
            lastx = dx;
        }
        if (t == -1) {
            alive += 1;
        } else if (t == 0) {
            pay += 1;
        } else {
            alive -= 1, pay -= 1;
        }
    }
    a.push_back(events.back().first);
//    for (int i = 0; i < c.size(); ++i) {
//        cout << a[i] << " " << c[i] << endl;
//    }
//    cout << a.back() << endl;

    ll ans = 0;
    for (int _ = 0; _ < 2; ++_) {
        ll sum = 0;
        for (int i = 0, j = 0; i + 1 < a.size(); ++i) {
            j = max(j, i);
            while (j + 1 < a.size() && a[j + 1] - a[i] <= x) {
                sum += 1LL * c[j] * (a[j + 1] - a[j]);
                j += 1;
            }
            int can = max(0, x - (a[j] - a[i]));
            ans = max(ans, sum + (j + 1 < a.size() ? can * 1LL * c[j] : 0LL));
            if (i + 1 <= j) {
                sum -= c[i] * 1LL * (a[i + 1] - a[i]);
            }
        }
        reverse(a.begin(), a.end());
        reverse(c.begin(), c.end());
        for (int &ty : a) {
            ty = -ty;
        }
    }
    cout << ans << '\n';

    return 0;
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:51:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for (int i = 0, j = 0; i + 1 < a.size(); ++i) {
      |                                ~~~~~~^~~~~~~~~~
autobahn.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             while (j + 1 < a.size() && a[j + 1] - a[i] <= x) {
      |                    ~~~~~~^~~~~~~~~~
autobahn.cpp:58:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             ans = max(ans, sum + (j + 1 < a.size() ? can * 1LL * c[j] : 0LL));
      |                                   ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 54 ms 10168 KB Output is correct
22 Correct 54 ms 10436 KB Output is correct
23 Correct 55 ms 10988 KB Output is correct
24 Correct 51 ms 11388 KB Output is correct
25 Correct 52 ms 11176 KB Output is correct
26 Correct 50 ms 12224 KB Output is correct
27 Correct 48 ms 11060 KB Output is correct
28 Correct 50 ms 10688 KB Output is correct
29 Correct 57 ms 12808 KB Output is correct