제출 #1168655

#제출 시각아이디문제언어결과실행 시간메모리
1168655LinkedArrayFuel Station (NOI20_fuelstation)C++17
24 / 100
261 ms18000 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define pb push_back

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;

int 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...