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 500
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N], pp[N], qq[N];
int compare_x(int i, int j) {
return xx[i] - xx[j];
}
int compare_pq(int i, int j) {
return pp[i] * qq[j] - pp[j] * qq[i];
}
int (*compare)(int, int);
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) {
int c = compare(ii[j], i_);
if (c == 0)
j++;
else if (c < 0) {
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;
}
}
int ft[N];
void update(int i, int n, int x) {
while (i < n) {
ft[i] = max(ft[i], x);
i |= i + 1;
}
}
int query(int i) {
int x = 0;
while (i >= 0) {
x = max(x, ft[i]);
i &= i + 1, i--;
}
return x;
}
int main() {
static int ii[N];
int n, l, i;
scanf("%d%d", &l, &n);
for (i = 0; i < n; i++) {
int t, v;
scanf("%d%d", &t, &v);
xx[i] = t, pp[i] = l + t * v, qq[i] = v;
}
for (i = 0; i < n; i++)
ii[i] = i;
compare = compare_x, sort(ii, 0, n);
for (i = 0; i < n; i++)
xx[ii[i]] = i;
compare = compare_pq, sort(ii, 0, n);
for (i = n - 1; i >= 0; i--)
update(xx[ii[i]], n, query(xx[ii[i]] - 1) + 1);
printf("%d\n", query(n - 1));
return 0;
}
Compilation message (stderr)
walking.c: In function 'main':
walking.c:70:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d%d", &l, &n);
| ^~~~~~~~~~~~~~~~~~~~~
walking.c:74:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | scanf("%d%d", &t, &v);
| ^~~~~~~~~~~~~~~~~~~~~
# | 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... |