이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |