//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;
constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;
random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());
template<typename T>
bool assign_max(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_min(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
T square(T a) {
return a * a;
}
template<>
struct std::hash<pair<ll, ll>> {
ll operator() (pair<ll, ll> p) const {
return ((__int128)p.first * MOD + p.second) % INF64;
}
};
void solve() {
ll n, k, x;
cin >> n >> k >> x;
deque<tuple<ll, ll, ll>> arr;
vector<pair<ll, ll>> s;
for (ll i = 0; i < n; i++) {
ll l, t, r;
cin >> l >> t >> r;
s.emplace_back(l, 2);
if (l + t <= r) {
s.emplace_back(l + t, 3);
s.emplace_back(r + 1, 1);
}
s.emplace_back(r + 1, 0);
}
sort(s.rbegin(), s.rend());
ll nc = 0, ns = 0;
ll lt = 0;
while (!s.empty()) {
auto[nt, t] = s.back();
s.pop_back();
if (nt != lt && nc >= k) {
arr.emplace_back(lt, nt, ns);
}
lt = nt;
if (t == 2) {
nc++;
}
if (t == 3) {
ns++;
}
if (t == 0) {
nc--;
}
if (t == 1) {
ns--;
}
}
set<ll> as;
for (auto[l, r, c] : arr) {
as.insert(l);
as.insert(r - x);
as.insert(r);
as.insert(l - x);
}
auto ba = arr, ea = arr;
ll nans = 0;
ll ans = 0;
for (auto i : as) {
ll ne = i + x;
while (!ea.empty() && get<0>(ea.front()) < ne) {
auto[l, r, c] = ea.front();
ea.pop_front();
if (r > ne) {
nans += (ne - l) * c;
l = ne;
ea.emplace_front(l, r, c);
} else {
nans += (r - l) * c;
}
}
while (!ba.empty() && get<0>(ba.front()) < i) {
auto[l, r, c] = ba.front();
ba.pop_front();
if (r > i) {
nans -= (i - l) * c;
l = i;
ba.emplace_front(l, r, c);
} else {
nans -= (r - l) * c;
}
}
assign_max(ans, nans);
}
cout << ans << '\n';
}
int main() {
if (IS_FILE) {
freopen("", "r", stdin);
freopen("", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
if (IS_TEST_CASES) {
cin >> t;
}
for (ll i = 0; i < t; i++) {
solve();
}
}
Compilation message
autobahn.cpp: In function 'int main()':
autobahn.cpp:129:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
129 | freopen("", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~
autobahn.cpp:130:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
130 | freopen("", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 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 |
1 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 |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 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 |
1 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 |
604 KB |
Output is correct |
21 |
Correct |
132 ms |
35256 KB |
Output is correct |
22 |
Correct |
134 ms |
34988 KB |
Output is correct |
23 |
Correct |
127 ms |
34740 KB |
Output is correct |
24 |
Correct |
157 ms |
35508 KB |
Output is correct |
25 |
Correct |
144 ms |
33716 KB |
Output is correct |
26 |
Correct |
150 ms |
33720 KB |
Output is correct |
27 |
Correct |
154 ms |
34916 KB |
Output is correct |
28 |
Correct |
159 ms |
35876 KB |
Output is correct |
29 |
Correct |
155 ms |
34232 KB |
Output is correct |