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 M 500000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int ll[M], rr[M];
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k)
if (ll[hh[j]] == ll[h])
j++;
else if (ll[hh[j]] < ll[h]) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
sort(hh, l, i);
l = k;
}
}
int main() {
static int ww[M], hh[M];
int n, m, k, l, h, h_, i, wl, wr, r, ans;
scanf("%d%d", &l, &n);
m = 0;
for (i = 0; i < n; i++) {
scanf("%d", &k);
wr = 0;
for (h = 0; h < k; h++) {
scanf("%d", &ww[h]);
wr += ww[h];
}
wl = 0;
for (h = 0; h < k; h++) {
wl += ww[h];
if (l - wr < wl)
ll[m] = l - wr, rr[m] = wl, m++;
wr -= ww[h];
}
}
for (h = 0; h < m; h++)
hh[h] = h;
sort(hh, 0, m);
ans = 0;
for (h = 0, r = 0; h < m; h++) {
h_ = hh[h];
if (r < ll[h_])
ans += rr[h_] - ll[h_], r = rr[h_];
else if (r < rr[h_])
ans += rr[h_] - r, r = rr[h_];
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
lasers.c: In function 'main':
lasers.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d", &l, &n);
| ^~~~~~~~~~~~~~~~~~~~~
lasers.c:39:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d", &k);
| ^~~~~~~~~~~~~~~
lasers.c:42:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d", &ww[h]);
| ^~~~~~~~~~~~~~~~~~~
# | 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... |