#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, k, x;
cin >> n >> k >> x;
vector<pair<int,int>> sweep;
sweep.push_back({0, 0});
int qtd[300100]={}, il[300100]={}, c[300100]={};
for(int i=0; i<n; i++){
int l, t, r;
cin >> l >> t >> r;
sweep.push_back({l-1, 0});
sweep.push_back({min(l+t-1, r), 1});
sweep.push_back({r, 2});
}
sort(sweep.begin(), sweep.end());
for(int i=1; i<sweep.size(); i++){
if(qtd[i-1]>=k){
c[i]=il[i-1]*(sweep[i].first-sweep[i-1].first);
}
if(sweep[i].second==0){
qtd[i]=qtd[i-1]+1;
il[i]=il[i-1];
}
else if(sweep[i].second==1){
qtd[i]=qtd[i-1];
il[i]=il[i-1]+1;
}
else{
qtd[i]=qtd[i-1]-1;
il[i]=il[i-1]-1;
}
}
int pref[300100]={}, suf[300100]={};
for(int i=1; i<sweep.size(); i++){
pref[i]=pref[i-1]+c[i];
}
for(int i=sweep.size()-2; i>0; i--){
suf[i]=suf[i+1]+c[i+1];
}
int resp=0;
for(int i=1; i<sweep.size(); i++){
if(sweep[i].first<=x)resp=max(resp, pref[i]);
else{
int ini=1, fim=i;
int pos=0;
while(ini<=fim){
int mid=(ini+fim)/2;
if(sweep[i].first-sweep[mid].first<=x){
pos=mid;
fim=mid-1;
}
else ini=mid+1;
}
int cr=pref[i]-pref[pos];
cr+=(qtd[pos-1]>=k)*il[pos-1]*(x-(sweep[i].first-sweep[pos].first));
if(pos!=0)resp=max(resp, cr);
}
if(sweep.back().first-sweep[i].first<=x)resp=max(resp, suf[i]);
else{
int ini=i, fim=sweep.size()-2;
int pos=0;
while(ini<=fim){
int mid=(ini+fim)/2;
if(sweep[mid].first-sweep[i].first<=x){
pos=mid;
ini=mid+1;
}
else fim=mid-1;
}
int cr=suf[i]-suf[pos];
cr+=(qtd[pos]>=k)*il[pos]*(x-(sweep[pos].first-sweep[i].first));
if(pos!=0)resp=max(cr, resp);
}
}
cout << resp << '\n';
}
Compilation message
autobahn.cpp: In function 'int main()':
autobahn.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=1; i<sweep.size(); i++){
| ~^~~~~~~~~~~~~
autobahn.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=1; i<sweep.size(); i++){
| ~^~~~~~~~~~~~~
autobahn.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=1; i<sweep.size(); i++){
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6236 KB |
Output is correct |
2 |
Correct |
4 ms |
6236 KB |
Output is correct |
3 |
Correct |
4 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6236 KB |
Output is correct |
6 |
Correct |
4 ms |
6236 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6152 KB |
Output is correct |
9 |
Correct |
3 ms |
6232 KB |
Output is correct |
10 |
Correct |
3 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6236 KB |
Output is correct |
2 |
Correct |
4 ms |
6236 KB |
Output is correct |
3 |
Correct |
4 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6236 KB |
Output is correct |
6 |
Correct |
4 ms |
6236 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6152 KB |
Output is correct |
9 |
Correct |
3 ms |
6232 KB |
Output is correct |
10 |
Correct |
3 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6232 KB |
Output is correct |
12 |
Correct |
4 ms |
6236 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
4 ms |
6236 KB |
Output is correct |
15 |
Correct |
4 ms |
6236 KB |
Output is correct |
16 |
Correct |
4 ms |
6204 KB |
Output is correct |
17 |
Correct |
3 ms |
6236 KB |
Output is correct |
18 |
Correct |
3 ms |
6384 KB |
Output is correct |
19 |
Correct |
3 ms |
6236 KB |
Output is correct |
20 |
Correct |
4 ms |
6364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6236 KB |
Output is correct |
2 |
Correct |
4 ms |
6236 KB |
Output is correct |
3 |
Correct |
4 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6236 KB |
Output is correct |
6 |
Correct |
4 ms |
6236 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6152 KB |
Output is correct |
9 |
Correct |
3 ms |
6232 KB |
Output is correct |
10 |
Correct |
3 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6232 KB |
Output is correct |
12 |
Correct |
4 ms |
6236 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
4 ms |
6236 KB |
Output is correct |
15 |
Correct |
4 ms |
6236 KB |
Output is correct |
16 |
Correct |
4 ms |
6204 KB |
Output is correct |
17 |
Correct |
3 ms |
6236 KB |
Output is correct |
18 |
Correct |
3 ms |
6384 KB |
Output is correct |
19 |
Correct |
3 ms |
6236 KB |
Output is correct |
20 |
Correct |
4 ms |
6364 KB |
Output is correct |
21 |
Incorrect |
60 ms |
13008 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |