Submission #1309794

#TimeUsernameProblemLanguageResultExecution timeMemory
1309794edoAutobahn (COI21_autobahn)C++20
100 / 100
85 ms17432 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; using pii = pair<int,int>; using pll = pair<ll,ll>; using ui = unsigned int; using ull = unsigned long long; using pui = pair<ui,ui>; using pull = pair<ull,ull>; using i128 = __int128_t; template<typename T> using vc = std::vector<T>; #define YES cout << "YES\n" #define NO cout << "NO\n" #define yes cout << "yes\n" #define no cout << "no\n" #define Yes cout << "Yes\n" #define No cout << "No\n" template<typename T> void sc(T &x) { cin >> x; } template<typename T, typename U> void sc(pair<T,U> &p) { sc(p.first), sc(p.second); } template<typename T> void sc(vector<T> &v) { for (auto &x : v) sc(x); } template<typename... A> void sc(A&... a) { (sc(a), ...); } template<typename T> void _pt(const T &x){cout << x;} template<typename T, typename U> void _pt(const pair<T,U> &p){_pt(p.first); cout << ' '; _pt(p.second);} template<typename T> void _pt(const vector<T> &v){bool f=1; for(auto &x:v){if(!f) cout<<' '; _pt(x); f=0;}} template<typename... A> void pt(const A&... a){(_pt(a), ...);} template<typename T, typename U> bool umin(T &a, const U &b) { return b < a ? (a = b, true) : false; } template<typename T, typename U> bool umax(T &a, const U &b) { return b > a ? (a = b, true) : false; } template<typename T> T maxel(const vector<T>& v){ return *max_element(v.begin(), v.end()); } template<typename T> T minel(const vector<T>& v){ return *min_element(v.begin(), v.end()); } template<typename T, int N> T maxel(T (&a)[N]) { return *max_element(a, a + N); } template<typename T, int N> T minel(T (&a)[N]) { return *min_element(a, a + N); } template<typename C, typename T> auto lb(C& c, const T& x){ return std::lower_bound(c.begin(), c.end(), x); } template<typename C, typename T> auto ub(C& c, const T& x){ return std::upper_bound(c.begin(), c.end(), x); } template<typename T> auto lb(std::set<T>& s, const T& x){ return s.lower_bound(x); } template<typename T> auto ub(std::set<T>& s, const T& x){ return s.upper_bound(x); } template<typename T> auto lb(const std::set<T>& s, const T& x){ return s.lower_bound(x); } template<typename T> auto ub(const std::set<T>& s, const T& x){ return s.upper_bound(x); } #define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME #define FOR1(n) for (int i=0; i<(n); ++i) #define FOR2(i,n) for (int i=0; i<(n); ++i) #define FOR3(i,l,r) for (int i=(l); i<(r); ++i) #define FOR4(i,l,r,k) for (int i=(l); i<(r); i+=(k)) #define FOR(...) GET_MACRO(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define ROF1(n) for (int i=(n)-1; i>=0; --i) #define ROF2(i,n) for (int i=(n)-1; i>=0; --i) #define ROF3(i,l,r) for (int i=(r)-1; i>=(l); --i) #define ROF4(i,l,r,k) for (int i=(r)-1; i>=(l); i-=(k)) #define ROF(...) GET_MACRO(__VA_ARGS__, ROF4, ROF3, ROF2, ROF1)(__VA_ARGS__) #define all(c) (c).begin(), (c).end() #define allr(c) (c).rbegin(), (c).rend() #define eb emplace_back #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define trav(x,a) for (auto &x : (a)) #define sz(a) ((int)(a).size()) #define mem(a,v) memset(a, v, sizeof(a)) #define nl pt("\n") int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k, x; sc(n, k, x); vc<pii> occE; vc<pii> extW; vi xs; FOR(n) { int l, t, r; sc(l, t, r); r++; xs.pb(l); xs.pb(r); occE.eb(l, 1); occE.eb(r, -1); if(l + t < r) { xs.pb(l + t); extW.eb(l + t, 1); extW.eb(r, -1); } } sort(all(occE)); sort(all(extW)); sort(all(xs)); xs.erase(unique(all(xs)), xs.end()); int M = sz(xs); vll A(M), W(M); { int p = 0, i = 0; while(i < sz(occE)) { ll sum = 0; int tm = occE[i].fi; while(i < sz(occE) && occE[i].fi == tm) { sum += occE[i].se; i++; } while(p < M && xs[p] < tm) p++; if(p < M && xs[p] == tm) A[p] += sum; } } { int p = 0, i = 0; while(i < sz(extW)) { ll sum = 0; int tm = extW[i].fi; while(i < sz(extW) && extW[i].fi == tm) { sum += extW[i].se; i++; } while(p < M && xs[p] < tm) p++; if(p < M && xs[p] == tm) W[p] += sum; } } vll segLen, segW; ll occ = 0, ext = 0; FOR(M - 1) { occ += A[i]; ext += W[i]; ll len = xs[i + 1] - xs[i]; ll w = occ >= k ? ext : 0; segLen.pb(len); segW.pb(w); } ll off = 0; int L = 0; ll totLen = 0; ll tot = 0; ll ans = 0; FOR(R, sz(segLen)) { totLen += segLen[R]; tot += segLen[R] * segW[R]; while(totLen > x) { ll need = totLen - x; ll can = segLen[L] - off; ll take = min(can, need); totLen -= take; tot -= take * segW[L]; off += take; if(segLen[L] == off) { off = 0; L++; } } umax(ans, tot); } pt(ans); nl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...