#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) (int)x.size()
#define fi first
#define sd second
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("avx2")
using namespace std;
using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll n, k, x;
gp_hash_table<int, ll> pref, in, out, skok;
gp_hash_table<int, bool> good;
ll ans = -1;
vector< int > vec;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(NULL);
cin >> n >> k >> x;
pref[0] = 0;
for(int i = 1; i <= n; i++)
{
int l, t, r;
cin >> l >> t >> r;
vec.pb(l);
vec.pb(l + t);
vec.pb(r);
if (l - x >= 1)
vec.pb(l - x);
if (l + t - x >= 1)
vec.pb(l + t - x);
if (r - x >= 1)
vec.pb(r - x);
in[l]++; out[r]++;
skok[l + t]++;
good[l] = 1; good[l + t] = 1; good[r] = 1;
}
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
ll cnt = 0, sum = 0, cur = 0, lst = -1;
for(const auto &i : vec)
{
if (cnt >= k && lst != -1) sum += (i - lst - 1)* 1ll * cur;
cnt += in[i];
cur += skok[i];
if (cnt >= k) sum += cur;
//cout << cnt << ' ' << cur << ' ' << i << endl;
cnt -= out[i];
cur -= out[i];
pref[i] = sum;
//ans = max(ans, sum);
lst = i;
}
//for(auto u : pref) cout << u.fi << ' ' << u.sd << endl;
for(const auto &i : vec)
{
if (!good[i]) continue;
if (i - x >= 0)
ans = max(ans, pref[i] - pref[i - x]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
550 ms |
249916 KB |
Output is correct |
22 |
Correct |
538 ms |
249720 KB |
Output is correct |
23 |
Correct |
562 ms |
249764 KB |
Output is correct |
24 |
Correct |
335 ms |
137680 KB |
Output is correct |
25 |
Correct |
360 ms |
138044 KB |
Output is correct |
26 |
Correct |
328 ms |
137640 KB |
Output is correct |
27 |
Correct |
293 ms |
137364 KB |
Output is correct |
28 |
Correct |
299 ms |
137340 KB |
Output is correct |
29 |
Correct |
300 ms |
137312 KB |
Output is correct |