This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 3e5 + 5;
struct station {
int a, b, x;
bool operator<(const station& other) const {
return x < other.x;
}
} v[MAXN];
signed main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, d;
cin >> n >> d;
++n;
for (int i = 1; i < n; ++i) cin >> v[i].x >> v[i].a >> v[i].b;
v[n].a = v[n].b = 0;
v[n].x = d;
sort(v + 1, v + n + 1);
int ans = 0, curf = 0;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
for (int i = 1; i <= n; ++i) {
if (curf < v[i].x) {
ans += v[i].x - curf;
curf = v[i].x;
}
while (!pq.empty() && pq.top().first < ans) {
curf -= pq.top().second; pq.pop();
if (curf < v[i].x) {
ans += v[i].x - curf;
curf = v[i].x;
}
}
if (ans <= v[i].b) {
curf += v[i].a;
pq.push({v[i].b, v[i].a});
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |