#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <random>
#include <deque>
using namespace std;
mt19937 rng(420691273);
#define ll long long
const int MX = 1e5 + 5;
int n, k, x;
struct dt{
int l, m, r;
} arr[MX];
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> k >> x;
vector<int> cc;
for(int i = 0; i < n; i ++){
cin >> arr[i].l >> arr[i].m >> arr[i].r;
arr[i].r ++; arr[i].m += arr[i].l;
cc.push_back(arr[i].l);
cc.push_back(arr[i].m);
cc.push_back(arr[i].r);
}
sort(cc.begin(), cc.end());
cc.erase(unique(cc.begin(), cc.end()), cc.end());
vector<int> cnt(cc.size() + 5, 0), ext(cc.size() + 5, 0);
for(int i = 0; i < n; i ++){
arr[i].l = lower_bound(cc.begin(), cc.end(), arr[i].l) - cc.begin();
arr[i].m = lower_bound(cc.begin(), cc.end(), arr[i].m) - cc.begin();
arr[i].r = lower_bound(cc.begin(), cc.end(), arr[i].r) - cc.begin();
cnt[arr[i].l] ++; cnt[arr[i].r] --;
ext[arr[i].m] ++; ext[arr[i].r] --;
}
for(int i = 1; i < cnt.size(); i ++){
cnt[i] += cnt[i - 1];
ext[i] += ext[i - 1];
}
ll ans = 0ll, res = 0ll;
// begin
for(int i = 0, j = -1; i < cc.size(); i ++){
for(; j + 2 < cc.size() && cc[j + 2] - cc[i] < x;){
j ++;
if(cnt[j] >= k)
res += (cc[j + 1] - cc[j]) * 1ll * ext[j];
}
ll tmp = 0ll;
if(j + 1 < cc.size() && cnt[j + 1] >= k)
tmp = (cc[i] + x - cc[j + 1]) * 1ll * ext[j + 1];
if(ans < res + tmp)
ans = res + tmp;
if(cnt[i] >= k)
res -= (cc[i + 1] - cc[i]) * 1ll * ext[i];
}
// end
res = 0ll;
for(int i = cc.size() - 1, j = cc.size() - 1; i >= 0; i --){
if(cnt[i] >= k)
res -= (cc[i + 1] - cc[i]) * 1ll * ext[i];
for(; j > 0 && cc[i] - cc[j - 1] < x;){
j --;
if(cnt[j] >= k)
res += (cc[j + 1] - cc[j]) * 1ll * ext[j];
}
ll tmp = 0ll;
if(j > 0 && cnt[j - 1] >= k)
tmp = (cc[j] - (cc[i] - x)) * 1ll * ext[j - 1];
if(ans < res + tmp)
ans = res + tmp;
}
cout << ans << endl;
return 0;
}
Compilation message
autobahn.cpp: In function 'int main()':
autobahn.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i = 1; i < cnt.size(); i ++){
| ~~^~~~~~~~~~~~
autobahn.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0, j = -1; i < cc.size(); i ++){
| ~~^~~~~~~~~~~
autobahn.cpp:51:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(; j + 2 < cc.size() && cc[j + 2] - cc[i] < x;){
| ~~~~~~^~~~~~~~~~~
autobahn.cpp:57:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | if(j + 1 < cc.size() && cnt[j + 1] >= k)
| ~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
324 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 |
336 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 |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
324 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 |
336 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 |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
123 ms |
7792 KB |
Output is correct |
22 |
Correct |
122 ms |
7588 KB |
Output is correct |
23 |
Correct |
123 ms |
7616 KB |
Output is correct |
24 |
Correct |
140 ms |
7640 KB |
Output is correct |
25 |
Correct |
125 ms |
7648 KB |
Output is correct |
26 |
Correct |
118 ms |
7708 KB |
Output is correct |
27 |
Correct |
126 ms |
7656 KB |
Output is correct |
28 |
Correct |
125 ms |
7868 KB |
Output is correct |
29 |
Correct |
123 ms |
7608 KB |
Output is correct |