#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k, x;
cin >> n >> k >> x;
map<int, array<int, 2>> ev;
for (int i = 0, l, t, r; i < n; i++) {
cin >> l >> t >> r;
ev[l][0]++, ev[r + 1][0]--;
if (l + t <= r) ev[l + t][1]++, ev[r + 1][1]--;
}
vector<array<int, 3>> inter;
int stay = 0, bad = 0, lst = 0;
for (auto [t, p] : ev) {
if (stay >= k) inter.push_back({lst, t - 1, bad});
stay += p[0], bad += p[1], lst = t;
}
vector<int> cand;
for (auto &p : inter) {
cand.insert(cand.end(), {p[0] - 1, p[0] + x - 1, p[1] - x, p[1]});
}
sort(cand.begin(), cand.end());
cand.resize(unique(cand.begin(), cand.end()) - cand.begin());
vector<ll> res(cand.size());
ll overlap = 0;
for (int i = 0, j = 0; i < cand.size(); i++) {
for (; j < inter.size() && inter[j][1] < cand[i]; j++) {
overlap += 1LL * (inter[j][1] - inter[j][0] + 1) * inter[j][2];
}
res[i] = overlap;
if (j < inter.size() && inter[j][0] <= cand[i]) {
res[i] += 1LL * (cand[i] - inter[j][0] + 1) * inter[j][2];
}
}
ll ans = 0;
for (auto &p : inter) {
int it1 = lower_bound(cand.begin(), cand.end(), p[0] - 1) - cand.begin();
int it2 = lower_bound(cand.begin(), cand.end(), p[0] + x - 1) - cand.begin();
ans = max(ans, res[it2] - res[it1]);
it1 = lower_bound(cand.begin(), cand.end(), p[1] - x) - cand.begin();
it2 = lower_bound(cand.begin(), cand.end(), p[1]) - cand.begin();
ans = max(ans, res[it2] - res[it1]);
}
cout << ans << "\n";
return 0;
}
Compilation message
autobahn.cpp: In function 'int main()':
autobahn.cpp:30:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0, j = 0; i < cand.size(); i++) {
| ~~^~~~~~~~~~~~~
autobahn.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (; j < inter.size() && inter[j][1] < cand[i]; j++) {
| ~~^~~~~~~~~~~~~~
autobahn.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (j < inter.size() && inter[j][0] <= cand[i]) {
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
323 ms |
32292 KB |
Output is correct |
22 |
Correct |
310 ms |
32168 KB |
Output is correct |
23 |
Correct |
343 ms |
32248 KB |
Output is correct |
24 |
Correct |
306 ms |
32352 KB |
Output is correct |
25 |
Correct |
305 ms |
32196 KB |
Output is correct |
26 |
Correct |
285 ms |
32068 KB |
Output is correct |
27 |
Correct |
306 ms |
32188 KB |
Output is correct |
28 |
Correct |
288 ms |
32236 KB |
Output is correct |
29 |
Correct |
319 ms |
32268 KB |
Output is correct |