//#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 + 1 <= 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 |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |