Submission #1168656

#TimeUsernameProblemLanguageResultExecution timeMemory
1168656LinkedArrayFuel Station (NOI20_fuelstation)C++17
67 / 100
247 ms26300 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back #define int ll const int MAX_N = 3e5; struct FuelStation { int d, maxl, th; }; FuelStation fs[MAX_N + 2]; set<pair<int, int>, greater<pair<int, int>>> rem; signed main () { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, d, i, sf, ff, fcap; cin >> n >> d; for (i = 1; i <= n; i++) { cin >> fs[i].d >> fs[i].maxl >> fs[i].th; } sort(fs + 1, fs + n + 1, [] (FuelStation s1, FuelStation s2) { return s1.d < s2.d; }); fs[n + 1] = {d, -1, d + 1}; sf = 0; ff = 0; for (i = 1; i <= n + 1; i++) { fcap = sf + ff; while (fs[i].d > fcap && sf <= fs[i].th) { sf = fs[i].d - ff; while (rem.size() > 0 && (*rem.begin()).first < sf) { ff -= (*rem.begin()).second; rem.erase(*rem.begin()); } fcap = sf + ff; } if (sf <= fs[i].th) { ff += fs[i].maxl; rem.emplace(fs[i].th, fs[i].maxl); } } cout << sf << "\n"; 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...