Submission #691273

#TimeUsernameProblemLanguageResultExecution timeMemory
691273ghostwriterFuel Station (NOI20_fuelstation)C++17
100 / 100
506 ms32948 KiB
#include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define bg begin #define ed end #define ft front #define bk back #define sz(x) (int)(x).size() #define all(x) (x).bg(), (x).ed() #define mtp make_tuple #define ins insert #define ers erase #define ll long long #define ull unsigned long long #define db double #define ldb long double #define str string #define pi pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vpi vector<pi> #define vpll vector<pll> #define FOR(i, l, r) for (int i = (l); i <= (r); ++i) #define FOS(i, r, l) for (int i = (r); i >= (l); --i) #define FRN(i, n) for (int i = 0; i < (n); ++i) #define FSN(i, n) for (int i = (n) - 1; i >= 0; --i) #define EACH(i, x) for (auto &i : (x)) #define WHILE while template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return b; } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } struct Station { int x, a, b; Station() {} Station(int x, int a, int b) : x(x), a(a), b(b) {} }; const ll oo = 1e18 + 5; const int N = 3e5 + 5; const int T = 12e5 + 5; int n, d; ll tr[T], la[T]; vpi d1; Station s[N]; bool cmp(const Station &a, const Station &b) { return a.x < b.x; } void lazy(int i) { if (!la[i]) return; tr[i] += la[i]; if (i * 2 + 1 < T) { la[i * 2] += la[i]; la[i * 2 + 1] += la[i]; } la[i] = 0; } void upd(int i, int l, int r, int ql, int qr, int v) { lazy(i); if (r < ql || l > qr) return; if (ql <= l && r <= qr) { la[i] += v; lazy(i); return; } int mid = l + (r - l) / 2; upd(i * 2, l, mid, ql, qr, v); upd(i * 2 + 1, mid + 1, r, ql, qr, v); tr[i] = min(tr[i * 2], tr[i * 2 + 1]); } ll get(int i, int l, int r, int ql, int qr) { lazy(i); if (r < ql || l > qr) return oo; if (ql <= l && r <= qr) return tr[i]; int mid = l + (r - l) / 2; return min(get(i * 2, l, mid, ql, qr), get(i * 2 + 1, mid + 1, r, ql, qr)); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n >> d; FOR(i, 1, n) cin >> s[i].x >> s[i].a >> s[i].b; sort(s + 1, s + 1 + n, cmp); FOR(i, 1, n) d1.pb({s[i].b, i}); sort(all(d1), greater<pi>()); ll sum = 0, rs = d; s[n + 1].x = s[n].x; FOR(i, 1, n) upd(1, 1, n, i, i, -s[i].x); EACH(z, d1) { int i = z.nd; sum += s[i].a; upd(1, 1, n, i + 1, n, s[i].a); ll minf = max({0LL, -tr[1], d - sum}); if (minf <= z.st) rs = min(rs, minf); } cout << rs; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...