#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e5;
vector<pair<int,int>> ev;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k,x;
cin>>n>>k>>x;
for(int i=1;i<=n;i++)
{
int l,r,t;
cin>>l>>t>>r;
if(l+t<=r)
{
ev.emplace_back(l+t,0);
ev.emplace_back(r+1,1);
}
ev.emplace_back(l,2);
ev.emplace_back(r+1,3);
}
sort(ev.begin(),ev.end());
int l=-x,r=0;
int cntl=0,cntr=0;
int opl=0,opr=0;
long long ans=0,tmp=0;
for(int i=0,j=0;i<ev.size();)
{
if(j>=ev.size() || ev[i].fi-l<ev[j].fi-r)
{
long long d=ev[i].fi-l;
if(opr>=k)
tmp+=d*cntr;
if(opl>=k)
tmp-=d*cntl;
l+=d;
r+=d;
if(ev[i].se==0)
cntl++;
else if(ev[i].se==1)
cntl--;
else if(ev[i].se==2)
opl++;
else
opl--;
i++;
}
else
{
long long d=ev[j].fi-r;
if(opr>=k)
tmp+=d*cntr;
if(opl>=k)
tmp-=d*cntl;
l+=d;
r+=d;
if(ev[j].se==0)
cntr++;
else if(ev[j].se==1)
cntr--;
else if(ev[j].se==2)
opr++;
else
opr--;
j++;
}
//cerr<<l<<" "<<r<<" "<<tmp<<"\n";
ans=max(ans,tmp);
}
cout<<ans<<"\n";
return 0;
}
Compilation message
autobahn.cpp: In function 'int main()':
autobahn.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0,j=0;i<ev.size();)
| ~^~~~~~~~~~
autobahn.cpp:33:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if(j>=ev.size() || ev[i].fi-l<ev[j].fi-r)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
88 ms |
6548 KB |
Output is correct |
22 |
Correct |
87 ms |
6508 KB |
Output is correct |
23 |
Correct |
89 ms |
6584 KB |
Output is correct |
24 |
Correct |
85 ms |
6604 KB |
Output is correct |
25 |
Correct |
86 ms |
6560 KB |
Output is correct |
26 |
Correct |
87 ms |
6588 KB |
Output is correct |
27 |
Correct |
84 ms |
6516 KB |
Output is correct |
28 |
Correct |
84 ms |
6596 KB |
Output is correct |
29 |
Correct |
86 ms |
6460 KB |
Output is correct |