This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
const int inf = 1e16;
const int N = 1e3 + 5;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, k, x;
cin>>n>>k>>x;
vector<array<int, 3> > upd;
for(int i = 0; i < n; i++){
int l, t, r;
cin>>l>>t>>r;
if(r - l + 1 > t){
upd.pb({l, i, 0});
upd.pb({l+t, i, 1});
upd.pb({r+1, i, 2});
}
else{
upd.pb({l, i, 0});
upd.pb({r+1, i, 2});
}
}
sort(upd.begin(), upd.end());
vector<int> col(n); // 0 yok, 1 iceride, 2 oduyor
vector<int> odeme(N);
int act = 0, ode = 0, ind = 0;
for(int i = 0; i <= N; i++){
while(ind < upd.size() && upd[ind][0] <= i){
if(upd[ind][2] == 0){
act++;
col[upd[ind][1]] = 1;
}
else if(upd[ind][2] == 1){
col[upd[ind][1]] = 2;
ode++;
}
else{
if(col[upd[ind][1]] == 2) ode--;
act--;
col[upd[ind][1]] = 0;
}
ind++;
}
if(act >= k) odeme[i] = ode;
}
int hh = 0;
for(int i = 0; i < x; i++){
hh += odeme[i];
}
int ans = hh;
for(int i = x; i < N; i++){
hh += odeme[i];
hh -= odeme[i - x];
ans = max(ans, hh);
}
cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
autobahn.cpp: In function 'int32_t main()':
autobahn.cpp:37:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | while(ind < upd.size() && upd[ind][0] <= i){
| ~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |