#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K, X;
cin >> N >> K >> X;
vector l(N, 0), r(N, 0), t(N, 0);
for(int i = 0; i < N; i++) { cin >> l[i] >> t[i] >> r[i]; r[i]++; }
vector P(0, 0);
for(int i = 0; i < N; i++) { P.push_back(l[i]), P.push_back(r[i]); }
for(int i = 0; i < N; i++) { if(l[i]+t[i] < r[i]) { P.push_back(l[i]+t[i]); } }
int sizep(size(P));
for(int i = 0; i < sizep; i++) { P.push_back(P[i]+X), P.push_back(P[i]-X); }
sort(begin(P), end(P));
P.erase(unique(begin(P), end(P)), end(P));
map<int, int> mp;
for(int i = 0; i < (int)size(P); i++) { mp[P[i]] = i; }
vector imos(size(P), 0);
for(int i = 0; i < N; i++) { imos[mp[l[i]]]++; imos[mp[r[i]]]--; }
for(int i = 0; i+1 < (int)size(P); i++) { imos[i+1] += imos[i]; }
vector imos2(size(P), 0LL);
for(int i = 0; i < N; i++) { if(l[i]+t[i] < r[i]) { imos2[mp[l[i]+t[i]]]++; imos2[mp[r[i]]]--; } }
for(int i = 0; i+1 < (int)size(P); i++) { imos2[i+1] += imos2[i]; }
for(int i = 0; i < (int)size(P); i++) { if(imos[i] < K) { imos2[i] = 0; } }
long long ans(0LL), res(0LL);
for(int i = 0, j = 0; i+1 < (int)size(P); i++) {
for(; j < (int)size(P); j++) {
if(P[i]+X <= P[j]) { break; }
else if(j+1 < (int)size(P)) { res += imos2[mp[P[j]]] * (long long)(P[j+1]-P[j]); }
}
ans = max(res, ans);
res -= imos2[mp[P[i]]] * (long long)(P[i+1] - P[i]);
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1 ms |
344 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1 ms |
344 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1 ms |
344 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
0 ms |
344 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |