#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define fr first
#define sc second
int n, k, x;
map<int,ll> qtd, val, pref;
set<int> zerar;
ll prefix(int ind) {
auto ptr = pref.upper_bound(ind);
if(ptr == pref.begin()) return 0;
ptr--;
ll resp = (*ptr).sc + val[(*ptr).fr] * (ind - (*ptr).fr);
return resp;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> x;
for(int i = 0, a, b, c; i < n; i++) {
cin >> a >> c >> b;
qtd[a]++;
qtd[b+1]--;
val[a+c]++;
val[b+1]--;
if(qtd.count(a+c) == 0) qtd[a+c] = 0;
if(val.count(a) == 0) val[a] = 0;
}
int at = 0;
for(auto [ind, a] : qtd) {
at += a;
qtd[ind] = at;
if(at < k) zerar.insert(ind);
}
at = 0;
ll p = 0, last_ind = 0, last_val = 0;
for(auto [ind, a] : val) {
at += a;
int at2 = at;
if(zerar.count(ind)) at2 = 0;
p += last_val * (ind - last_ind);
pref[ind] = p + at2;
val[ind] = at2;
last_ind = ind;
last_val = at2;
}
ll ans = 0;
for(auto [ind, a] : val) {
ll a1 = prefix(ind) - prefix(ind - x);
ll a2 = prefix(ind + x - 1) - prefix(ind - 1);
ll a3 = prefix(ind + x - 2) - prefix(ind - 2);
ll a4 = prefix(ind - 1) - prefix(ind - x - 1);
//cout << ind << " " << a1 << " " << a2 << "\n";
ans = max({ans, a1, a2, a3, a4});
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
746 ms |
65620 KB |
Output is correct |
22 |
Correct |
733 ms |
65620 KB |
Output is correct |
23 |
Correct |
751 ms |
65616 KB |
Output is correct |
24 |
Correct |
744 ms |
65620 KB |
Output is correct |
25 |
Correct |
733 ms |
65872 KB |
Output is correct |
26 |
Correct |
698 ms |
65976 KB |
Output is correct |
27 |
Correct |
634 ms |
65872 KB |
Output is correct |
28 |
Correct |
682 ms |
65620 KB |
Output is correct |
29 |
Correct |
697 ms |
65620 KB |
Output is correct |