Submission #1081626

#TimeUsernameProblemLanguageResultExecution timeMemory
1081626juicyAutobahn (COI21_autobahn)C++17
100 / 100
186 ms22088 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 1e5 + 5; int n, k, L; int l[N], r[N], t[N], a[9 * N], b[9 * N]; long long pf[9 * N]; void upd(int i, int j, int *a) { ++a[i]; --a[j]; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k >> L; vector<int> comp; for (int i = 1; i <= n; ++i) { cin >> l[i] >> t[i] >> r[i]; comp.push_back(l[i]); comp.push_back(r[i] + 1); if (r[i] - l[i] + 1 <= t[i]) { t[i] = -1; continue; } comp.push_back(l[i] + t[i]); } int m = comp.size(); for (int i = 0; i < m; ++i) { comp.push_back(comp[i] + L); comp.push_back(comp[i] - L); } sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); auto pos = [&](int i) { return lower_bound(comp.begin(), comp.end(), i) - comp.begin() + 1; }; m = comp.size(); for (int i = 1; i <= n; ++i) { int x = pos(l[i]), y = pos(r[i] + 1); upd(x, y, a); if (~t[i]) { int z = pos(l[i] + t[i]); upd(z, y, b); } } for (int i = 1; i <= m; ++i) { a[i] += a[i - 1]; b[i] += b[i - 1]; if (i + 1 <= m) { pf[i + 1] = pf[i] + (long long) (comp[i] - comp[i - 1]) * (a[i] >= k ? b[i] : 0); } } long long res = 0; for (int i = 1; i <= m; ++i) { int y = pos(comp[i - 1] + L); if (y <= m && comp[y - 1] == comp[i - 1] + L) { res = max(res, pf[y] - pf[i]); } } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...