This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define N 300001
#define N_ (1 << 19) /* N_ = pow2(ceil(log2(N))) */
long long max(long long a, long long b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N], aa[N], bb[N], ii[N], idx[N], n;
int *vv;
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k)
if (vv[ii[j]] == vv[i_])
j++;
else if (vv[ii[j]] < vv[i_]) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
sort(ii, l, i);
l = k;
}
}
long long ss[N_ * 2], pp[N_ * 2]; int n_;
void pul(int i) {
int l = i << 1, r = l | 1;
ss[i] = ss[l] + ss[r];
pp[i] = max(pp[l], pp[r] - ss[l]);
}
void build() {
int i;
n_ = 1;
while (n_ < n)
n_ <<= 1;
for (i = 0; i < n_; i++)
if (i < n)
ss[n_ + i] = aa[ii[i]], pp[n_ + i] = xx[ii[i]];
else
ss[n_ + i] = 0, pp[n_ + i] = 0;
for (i = n_ - 1; i > 0; i--)
pul(i);
}
void update(int i) {
ss[i += n_] = 0;
while (i > 1)
pul(i >>= 1);
}
int main() {
int x_, i;
scanf("%d%d", &n, &x_);
for (i = 0; i < n; i++)
scanf("%d%d%d", &xx[i], &aa[i], &bb[i]);
xx[n] = x_, aa[n] = 0, bb[n] = 0;
n++;
for (i = 0; i < n; i++)
ii[i] = i;
vv = xx, sort(ii, 0, n);
for (i = 0; i < n; i++)
idx[ii[i]] = i;
build();
vv = bb, sort(ii, 0, n);
for (i = 0; i < n; i++) {
if (pp[1] <= bb[ii[i]]) {
printf("%lld\n", pp[1]);
return 0;
}
update(idx[ii[i]]);
}
printf("%lld\n", pp[1]);
return 0;
}
Compilation message (stderr)
FuelStation.c: In function 'main':
FuelStation.c:70:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d%d", &n, &x_);
| ^~~~~~~~~~~~~~~~~~~~~~
FuelStation.c:72:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%d%d%d", &xx[i], &aa[i], &bb[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |