#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
int N,K,X;
vector<ii> events,overtime,charge;
int32_t main() {
#ifdef ACM
freopen("input","r",stdin);
#endif
cin>>N>>K>>X;
int l,t,r;
for(int i=0;i<N;i++) {
cin>>l>>t>>r;
if(l+t<=r) {
overtime.push_back({l+t,1});
overtime.push_back({r+1,-1});
}
events.push_back({l,1});
events.push_back({r+1,-1});
}
sort(events.begin(),events.end());
int people=0,pivot;
for(ii event:events) {
people+=event.second;
if(event.second==1&&people==K)
pivot=event.first;
else if(event.second==-1&&people==K-1) {
overtime.push_back({pivot,2});
overtime.push_back({event.first,-2});
}
}
sort(overtime.begin(),overtime.end());
//for(ii tmp:overtime)
// cerr<<tmp.first<<' '<<tmp.second<<'\n';
int numOvertime=0;
bool overload=false;
for(ii event:overtime) {
if(abs(event.second)==1)
numOvertime+=event.second;
else
overload=(event.second==2);
if(overload) {
if(charge.size()>0&&charge.back().first==event.first)
charge.back().second=numOvertime;
else
charge.push_back({event.first,numOvertime});
}
else if(charge.size()>0&&charge.back().first==event.first)
charge.back().second=0;
else
charge.push_back({event.first,0});
}
for(ii tmp:charge)
cerr<<tmp.first<<' '<<tmp.second<<'\n';
vector<int> S(charge.size());
for(int i=0;i<charge.size()-1;i++) {
S[i]=(charge[i+1].first-charge[i].first)*charge[i].second;
if(i>0)
S[i]+=S[i-1];
}
int cur=0,rs=0;
for(int i=0;i<charge.size()-1;i++) {
while(cur<charge.size()-1&&charge[cur+1].first<=charge[i].first+X-1)
cur++;
int sum=0;
if(cur>0)
sum=S[cur-1]-(i==0?0:S[i-1]);
sum+=(charge[i].first+X-charge[cur].first)*charge[cur].second;
rs=max(rs,sum);
}
cur=0;
for(int i=0;i<charge.size()-1;i++) {
while(cur<i&&charge[cur].first+X<charge[i+1].first)
cur++;
int sum=S[i]-(cur==0?0:S[cur-1]);
if(cur>0)
sum+=(charge[cur].first-charge[i+1].first+X)*charge[cur-1].second;
rs=max(rs,sum);
}
cout<<rs;
}
Compilation message
autobahn.cpp: In function 'int32_t main()':
autobahn.cpp:59:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0;i<charge.size()-1;i++) {
| ~^~~~~~~~~~~~~~~~
autobahn.cpp:65:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<charge.size()-1;i++) {
| ~^~~~~~~~~~~~~~~~
autobahn.cpp:66:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | while(cur<charge.size()-1&&charge[cur+1].first<=charge[i].first+X-1)
| ~~~^~~~~~~~~~~~~~~~
autobahn.cpp:75:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int i=0;i<charge.size()-1;i++) {
| ~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
332 KB |
Output is correct |
13 |
Correct |
7 ms |
332 KB |
Output is correct |
14 |
Correct |
7 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
8 ms |
332 KB |
Output is correct |
17 |
Correct |
6 ms |
332 KB |
Output is correct |
18 |
Correct |
8 ms |
428 KB |
Output is correct |
19 |
Correct |
7 ms |
332 KB |
Output is correct |
20 |
Correct |
7 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
332 KB |
Output is correct |
13 |
Correct |
7 ms |
332 KB |
Output is correct |
14 |
Correct |
7 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
8 ms |
332 KB |
Output is correct |
17 |
Correct |
6 ms |
332 KB |
Output is correct |
18 |
Correct |
8 ms |
428 KB |
Output is correct |
19 |
Correct |
7 ms |
332 KB |
Output is correct |
20 |
Correct |
7 ms |
332 KB |
Output is correct |
21 |
Execution timed out |
1093 ms |
15360 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |