#include <bits/stdc++.h>
#define int long long
#define inf 1e12
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n,k,x ;
cin>>n>>k>>x;
vector<int> l(n) ,t(n) , r(n) , events ;
for(int i=0;i<3000;i++) events.push_back(i) ;
for(int i=0;i<n;i++){
cin>>l[i]>>t[i]>>r[i] ;
int le = l[i],re=r[i],rr = l[i]+t[i]-1 ;
events.push_back(le);
events.push_back(re);
events.push_back(rr);
events.push_back(re+1) ;
events.push_back(rr+1) ;
events.push_back(re-x+1) ;
events.push_back(rr-x+1) ;
events.push_back(le-x+1);
events.push_back(re-x) ;
events.push_back(rr-x) ;
}
events.push_back(inf) ;
sort(all(events)) ;
auto it = unique(all(events),[&](int a ,int b){return a==b;}) ;
events.resize(distance(events.begin(),it)) ;
vector<int> illegals(events.size()) ;
vector<int> num(events.size()) ;
for(int i=0;i<n;i++){
int j = lower_bound(all(events),l[i])-events.begin() ;
num[j]++ ;
int k = lower_bound(all(events),r[i]+1)-events.begin() ;
num[k]-- ;
}
for(int i=0;i<n;i++){
int le = l[i],re=r[i] ,rr=l[i]+t[i]-1 ;
if(rr<=re){
int j = lower_bound(all(events),rr+1)-events.begin();
illegals[j]++;
j = lower_bound(all(events),re+1)-events.begin() ;
illegals[j]--;
}
}
for(int i=1;i<events.size();i++) num[i]+=num[i-1],illegals[i]+=illegals[i-1] ;
int curl = events[0] , curr =-inf, val = 0 , j = 0 , ans = 0 ;
/* for(int i=0;i<events.size();i++){
cout << "minute :" << events[i] << " " << num[i] << " "<< illegals[i] << endl ;
}*/
int goal = 0 ;
for(int i=0;i+1<events.size();i++){
curl=events[i] ;
if(curr<curl){
curr = curl ;
val = (int)(num[i]>=k)*illegals[i];
j=i+1 ;
}
else{
val-=(events[i]-events[i-1])*(illegals[i-1])*(int)(num[i-1]>=k) ;
}
while(curr-curl+1<x){
if(events[j]>x+curl-1){
val+=(curl+x-1-curr)*(illegals[j-1])*(int)(num[j-1]>=k) ;
curr = curl+x-1 ;
break ;
}
++j;
val+=(min(events[j]-1,curl+x-1)-curr)*(int)(num[j-1]>=k)*illegals[j-1] ;
curr = min(events[j]-1,curl+x-1) ;
}
if(val>ans){
ans=val;
goal = events[i] ;
}
// cout <<events[i] << " " << val << " " << j << " " << curr << endl ;
}
events.clear() ;
for(int i=0;i<n;i++){
int le = l[i],re=r[i],rr = l[i]+t[i]-1 ;
events.push_back(le);
events.push_back(re);
events.push_back(rr);
events.push_back(re+1) ;
events.push_back(rr+1) ;
events.push_back(re-x+1) ;
events.push_back(rr-x+1) ;
events.push_back(le-x+1);
events.push_back(re-x) ;
events.push_back(rr-x) ;
}
bool flg = 0 ;
for(int x:events) flg|=(x==goal) ;
assert(flg) ;
cout << ans ;
return 0;
}
Compilation message
autobahn.cpp: In function 'int main()':
autobahn.cpp:42:7: warning: unused variable 'le' [-Wunused-variable]
42 | int le = l[i],re=r[i] ,rr=l[i]+t[i]-1 ;
| ^~
autobahn.cpp:50:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=1;i<events.size();i++) num[i]+=num[i-1],illegals[i]+=illegals[i-1] ;
| ~^~~~~~~~~~~~~~
autobahn.cpp:56:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i=0;i+1<events.size();i++){
| ~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
404 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
404 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
4 ms |
572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
404 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
4 ms |
572 KB |
Output is correct |
21 |
Incorrect |
302 ms |
26476 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |