| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1349387 | icebear | Fuel Station (NOI20_fuelstation) | C++20 | 31 ms | 2724 KiB |
/* AUTHOR: TUAN ANH - BUI */
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class X, class Y>
bool minimize(X &x, const Y &y) {
if (x > y) return x = y, true;
return false;
}
template<class X, class Y>
bool maximize(X &x, const Y &y) {
if (x < y) return x = y, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
/*END OF TEMPLATE. I love my cats <3 */
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 27092008;
const ll INF = (ll)1e18 + 27092008;
const int N = 2e5 + 5;
int n, H;
struct Station {
int x, f, r;
bool operator < (const Station &other) const {
return x < other.x;
}
} S[N];
void init(void) {
cin >> n >> H;
FOR(i, 1, n) cin >> S[i].x >> S[i].f >> S[i].r;
sort(S + 1, S + n + 1);
}
void process(void) {
auto check = [&](long long V) {
int last = 0;
FOR(i, 1, n) {
V -= S[i].x - last;
if (V < 0) return false;
if (V <= S[i].r) V += S[i].f;
last = S[i].x;
}
V -= H - last;
return V >= 0;
};
int low = 0, high = H, res = 0;
while(low <= high) {
int mid = (low + high) >> 1;
if (check(mid)) res = mid, high = mid - 1;
else low = mid + 1;
}
cout << res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}Compilation message (stderr)
| # | 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... | ||||
