이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct FUEL {
long long int x, a, b;
} a[300005];
bool cmp(FUEL aa, FUEL bb) {
return aa.x < bb.x;
}
long long int t[1200005], lazy[1200005];
void push(int v) {
t[v * 2] += lazy[v];
lazy[v * 2] += lazy[v];
t[v * 2 + 1] += lazy[v];
lazy[v * 2 + 1] += lazy[v];
lazy[v] = 0;
}
void update(int v, int tl, int tr, int l, int r, int x) {
if (l > r) return;
if (tl == l && tr == r) {
t[v] += x;
lazy[v] += x;
return;
}
push(v);
int mid = (tl + tr) / 2;
update(v * 2, tl, mid, l, min(r, mid), x);
update(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
long long int sum(int v, int tl, int tr, int l, int r) {
if (l > r) return 0;
if (tl == l && tr == r) {
return t[v];
}
push(v);
int mid = (tl + tr) / 2;
return max(sum(v * 2, tl, mid, l, min(r, mid)), sum(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
long long int n, d, c = 0, res = 1e18;
cin >> n >> d;
vector<pair<long long int, int>> v;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].a >> a[i].b;
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; i++) {
v.push_back({a[i].b, i});
update(1, 1, n, i, i, a[i].x);
}
sort(v.begin(), v.end(), greater<pair<long long int, int>>());
res = d;
for (auto w : v) {
c += a[w.second].a;
update(1, 1, n, w.second + 1, n, -a[w.second].a);
long long int h = max(max(t[1], d - c), 0ll);
if (h <= w.first) {
res = min(res, h);
}
}
cout << res;
}
# | 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... |