#include "bits/stdc++.h"
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
void _(){
int n,k,X;
cin >> n >> k >> X;
array<int,3> ar[n+5];
for(int i=1;i<=n;i++) cin >> ar[i][0] >> ar[i][1] >> ar[i][2];
vector<int> zip,rev;
for(int i=1;i<=n;i++){
zip.push_back(ar[i][0]);
zip.push_back(ar[i][0]+ar[i][1]);
zip.push_back(ar[i][2]);
zip.push_back(ar[i][2]+1);
}
sort(all(zip));
zip.erase(unique(all(zip)),zip.end());
vector<int> sor = zip;
int _u = sz(zip);
for(int i=0;i<_u;i++){
zip.push_back(zip[i]-1);
zip.push_back(zip[i]+1);
zip.push_back(zip[i]-X+1);
zip.push_back(zip[i]+X-1);
zip.push_back(zip[i]-X);
zip.push_back(zip[i]+X);
}
sort(all(zip));
zip.erase(unique(all(zip)),zip.end());
rev.resize(sz(zip)+5);
for(int i=1;i<=sz(zip);i++) rev[i] = zip[i-1];
auto Get = [&](int u){
int it = lower_bound(all(zip),u) - zip.begin();
return it + 1;
};
vector<int> pre(sz(zip)+5,0);
for(int i=1;i<=n;i++){
pre[Get(ar[i][0])]++;
pre[Get(ar[i][2]+1)]--;
}
for(int i=1;i<=sz(zip);i++) pre[i] += pre[i-1];
for(int i=1;i<=sz(zip);i++) pre[i] = (pre[i] >= k);
vector<int> T(sz(zip)+5,0);
for(int i=1;i<=n;i++){
int l = ar[i][0] + ar[i][1];
int r = ar[i][2] + 1;
T[Get(l)]++,T[Get(r)]--;
}
for(int i=1;i<=sz(zip);i++) T[i]+=T[i-1];
for(int i=1;i<=sz(zip);i++){
T[i] *= pre[i];
if(i<sz(zip)) T[i] *= (rev[i + 1] - rev[i]);
}
for(int i=1;i<=sz(zip);i++) T[i]+=T[i-1];
int ans = 0;
for(int u:sor){
int l = u , r = u + X - 1;
ans = max(ans, T[Get(r)] - T[Get(l)-1]);
l = u - X + 1, r = u;
ans = max(ans, T[Get(r)] - T[Get(l)-1]);
l = u , r = u + X - 1;
ans = max(ans, T[Get(r)] - T[Get(l)]);
l = u - X + 1, r = u;
ans = max(ans, T[Get(r)] - T[Get(l)]);
}
cout << ans << '\n';
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
592 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
2 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
2 ms |
592 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
592 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
2 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
2 ms |
592 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
419 ms |
84824 KB |
Output is correct |
22 |
Correct |
426 ms |
84896 KB |
Output is correct |
23 |
Correct |
446 ms |
84832 KB |
Output is correct |
24 |
Correct |
425 ms |
84900 KB |
Output is correct |
25 |
Correct |
422 ms |
84908 KB |
Output is correct |
26 |
Correct |
412 ms |
84896 KB |
Output is correct |
27 |
Correct |
402 ms |
84908 KB |
Output is correct |
28 |
Correct |
399 ms |
84836 KB |
Output is correct |
29 |
Correct |
417 ms |
84880 KB |
Output is correct |