제출 #709701

#제출 시각아이디문제언어결과실행 시간메모리
709701awuFuel Station (NOI20_fuelstation)C++14
100 / 100
170 ms35524 KiB
#include <bits/extc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")

#define int long long
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) do{auto y = x; cout << #x << " = " << y << endl;}while(0)
// #define endl "\n"
#define unordered_map __gnu_pbds::gp_hash_table
using pii = pair<int, int>;

const int inf = 1ll << 60;
const int MOD = 1e9 + 7;

struct fuel {
  int x, a, b;
};
bool operator>(fuel a, fuel b) {
  return a.b > b.b;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, d; cin >> n >> d;
  vector<fuel> fs(n);
  for(int i = 0; i < n; i++) {
    cin >> fs[i].x >> fs[i].a >> fs[i].b;
  }
  fs.push_back({d, 0, 0});
  sort(all(fs), [](fuel a, fuel b) {
    return a.x < b.x;
  });
  priority_queue<fuel, vector<fuel>, greater<fuel>> pq;
  int sf = 0, cf = 0, pos = 0;
  for(auto f : fs) {
    cf -= f.x - pos;
    pos = f.x;
    if(cf < 0) {
      sf -= cf;
      cf = 0;
      while(pq.size() && pq.top().b < sf) {
        sf += pq.top().a;
        pq.pop();
      }
    }
    if(sf <= f.b) {
      cf += f.a;
      pq.push(f);
    }
  }
  cout << sf << endl;
}
#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...