Submission #959839

#TimeUsernameProblemLanguageResultExecution timeMemory
959839ono_de206Autobahn (COI21_autobahn)C++14
100 / 100
133 ms17548 KiB
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define in insert #define all(x) x.begin(),x.end() #define pb push_back #define eb emplace_back #define ff first #define ss second #define int long long typedef long long ll; typedef vector<int> vi; typedef set<int> si; typedef multiset<int> msi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<int, int> P; template<typename T, typename U> ostream & operator << (ostream &out, const pair<T, U> &c) { out << c.first << ' ' << c.second; return out; } template<typename T> ostream & operator << (ostream &out, vector<T> &v) { const int sz = v.size(); for (int i = 0; i < sz; i++) { if (i) out << ' '; out << v[i]; } return out; } template<typename T> istream & operator >> (istream &in, vector<T> &v) { for (T &x : v) in >> x; return in; } template<typename T, typename U> istream & operator >> (istream &in, pair<T, U> &c) { in >> c.first; in >> c.second; return in; } template<typename T> void mxx(T &a, T b){if(b > a) a = b;} template<typename T> void mnn(T &a, T b){if(b < a) a = b;} const int mxn = 5e5 + 10, MXLOG = 22, mod = 1e9 + 7; const long long inf = 1e18 + 10; void go() { int n, k, x; cin >> n >> k >> x; vector<pair<int, int>> A, B; for(int i = 1; i <= n; i++) { int l, t, r; cin >> l >> t >> r; A.eb(l, r); if(l + t <= r) B.eb(l + t, r); } vector<int> val; for(auto it : A) { val.pb(it.ff - 1); val.pb(it.ss); } for(auto it : B) { val.pb(it.ff - 1); val.pb(it.ss); } sort(all(val)); val.erase(unique(all(val)), val.end()); n = val.size(); vector<int> pre(n), ext(n), sum(n); for(auto it : A) { it.ff = lower_bound(all(val), it.ff) - val.begin(); it.ss = lower_bound(all(val), it.ss) - val.begin(); pre[it.ff]++; if(it.ss + 1 < n) pre[it.ss + 1]--; } for(auto it : B) { it.ff = lower_bound(all(val), it.ff) - val.begin(); it.ss = lower_bound(all(val), it.ss) - val.begin(); ext[it.ff]++; if(it.ss + 1 < n) ext[it.ss + 1]--; } for(int i = 1; i < n; i++) { pre[i] += pre[i - 1]; ext[i] += ext[i - 1]; if(pre[i] >= k) sum[i] = ext[i]; } int l = 0, now = 0, ans = 0; for(int i = 1; i < n; i++) { now += sum[i] * (val[i] - val[i - 1]); while(val[i] - val[l] > x) { l++; now -= sum[l] * (val[l] - val[l - 1]); } int need = x - (val[i] - val[l]); mxx(ans, now + need * sum[l]); } l = n - 1, now = 0; for(int i = n - 1; i > 0; i--) { now += sum[i] * (val[i] - val[i - 1]); while(val[l] - val[i - 1] > x) { now -= sum[l] * (val[l] - val[l - 1]); l--; } int need = x - (val[l] - val[i - 1]); mxx(ans, now); if(l + 1 < n) mxx(ans, now + need * sum[l + 1]); } cout << ans << endl; } signed main() { fast; int t = 1; // cin >> t; while(t--) { go(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...