#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<long long>
#define all(x) x.begin(), x.end()
#define endl "\n"
void solution();
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solution();
return 0;
}
const int MAXN = 1e4+10;
#define pr pair<ll, ll>
#define ff first
#define ss second
struct point {
ll X, A, B;
bool operator<(point temp) {
if (X == temp.X) return B < temp.B;
return X < temp.X;
}
};
point a[MAXN];
const ll inf = 1e18;
void solution() {
ll n, d; cin >> n >> d;
for (int i = 0; i < n; i++) {
cin >> a[i].X >> a[i].A >> a[i].B;
}
a[n].X = d;
a[n].A = 0;
a[n].B = 1e9;
n++;
sort(a, a+n);
for (ll fuel = 0; fuel <= d; fuel++) {
ll curr = fuel;
ll p = 0;
bool flag = true;
for (int i = 0; i < n; i++) {
if (a[i].X - p <= curr) {
curr -= a[i].X - p;
p = a[i].X;
if (fuel <= a[i].B) curr += a[i].A;
} else {
flag = false;
break;
}
}
if (flag) {
cout << fuel << endl;
return;
}
}
}
| # | 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... |