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 int long long
using namespace std;
int A[100005];
int B[100005];
int C[100005];
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N, K, X;
cin >> N >> K >> X;
int i, j;
for(i=0;i<N;i++) {
cin >> A[i] >> B[i] >> C[i];
}
vector<array<int, 2>> V;
for(i=0;i<N;i++) {
V.push_back({A[i], 1});
V.push_back({A[i]+B[i], 2});
V.push_back({C[i]+1, 3});
V.push_back({A[i]+X, 4});
V.push_back({A[i]+B[i]+X, 5});
V.push_back({C[i]+1+X, 6});
}
sort(V.begin(),V.end());
int ans = 0, val = 0, pl = 0, mi = 0, cnt1 = 0, cnt2 = 0;
int prv = -1;
for(auto it : V) {
val += (it[0] - prv) * ( (cnt1 >= K ? pl : 0) - (cnt2 >= K ? mi : 0));
if(it[1]==1) cnt1++;
if(it[1]==2) pl++;
if(it[1]==3) pl--, cnt1--;
if(it[1]==4) cnt2++;
if(it[1]==5) mi++;
if(it[1]==6) mi--, cnt2--;
prv = it[0];
ans = max(ans, val);
//cout << "Add in " << it[0] << ", type is " << it[1] << '\n';
//cout << val << ' ' << cnt1 << ' ' << pl << ' ' << cnt2 << ' ' << mi << '\n';
}
cout << ans;
}
Compilation message (stderr)
autobahn.cpp: In function 'int main()':
autobahn.cpp:13:12: warning: unused variable 'j' [-Wunused-variable]
13 | int i, j;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |