#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
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 |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
118 ms |
21896 KB |
Output is correct |
22 |
Correct |
123 ms |
21868 KB |
Output is correct |
23 |
Correct |
104 ms |
21912 KB |
Output is correct |
24 |
Correct |
106 ms |
22088 KB |
Output is correct |
25 |
Correct |
106 ms |
21936 KB |
Output is correct |
26 |
Correct |
107 ms |
21892 KB |
Output is correct |
27 |
Correct |
108 ms |
21904 KB |
Output is correct |
28 |
Correct |
107 ms |
21852 KB |
Output is correct |
29 |
Correct |
114 ms |
21884 KB |
Output is correct |