#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 300300;
int n, d, t[N * 4], lz[N * 4];
vector<int> ns;
struct station {
int x, a, b;
station (int _x = 0, int _a = 0, int _b = 0):
x(_x), a(_a), b(_b){};
const bool operator< (const station &oth){
return b < oth.b;
}
} a[N];
void push (int id, int l, int r){
if (l == r || lz[id] == 0){
return;
}
int &x = lz[id];
t[id * 2] += x;
t[id * 2 + 1] += x;
lz[id * 2] += x;
lz[id * 2 + 1] += x;
x = 0;
return;
}
void upd (int id, int l, int r, int u, int v, int x){
push(id, l, r);
if (l > v || r < u){
return;
}
if (l >= u && r <= v){
t[id] += x;
lz[id] += x;
return;
}
int m = (l + r) >> 1;
upd(id * 2, l, m, u, v, x);
upd(id * 2 + 1, m + 1, r, u, v, x);
t[id] = max(t[id * 2], t[id * 2 + 1]);
return;
}
bool vis[N];
int32_t main (){
ios::sync_with_stdio(false); cin.tie(nullptr);
const string task = "test";
if (fopen ((task + ".inp").c_str(), "r")){
freopen ((task + ".inp").c_str(), "r", stdin);
freopen ((task + ".out").c_str(), "w", stdout);
}
cin >> n >> d;
ns.push_back(0);
ns.push_back(d);
for (int i = 1; i <= n; ++i){
cin >> a[i].x >> a[i].a >> a[i].b;
ns.push_back(a[i].x);
}
sort(ns.begin(), ns.end());
ns.erase(unique(ns.begin(), ns.end()), ns.end());
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i){
a[i].x = lower_bound(ns.begin(), ns.end(), a[i].x) - ns.begin();
}
upd(1, 1, ns.size() - 1, ns.size() - 1, ns.size() - 1, d);
int ans = d;
for (int i = n; i >= 1; --i){
if (a[i].x != ns.size() - 1){
upd(1, 1, ns.size() - 1, a[i].x + 1, ns.size() - 1, -a[i].a);
}
if (!vis[a[i].x]){
upd(1, 1, ns.size() - 1, a[i].x, a[i].x, ns[a[i].x]);
}
vis[a[i].x] = true;
if (t[1] <= a[i].b){
ans = min(ans, t[1]);
}
}
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
FuelStation.cpp: In function 'int32_t main()':
FuelStation.cpp:60:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen ((task + ".inp").c_str(), "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FuelStation.cpp:61:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen ((task + ".out").c_str(), "w", stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |