Submission #944502

#TimeUsernameProblemLanguageResultExecution timeMemory
944502rainboy택배 (KOI13_delivery)C11
100 / 100
4 ms756 KiB
#include <stdio.h> #define N 10000 int min(int a, int b) { return a < b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int xx[N * 2], cc[N]; 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 = xx[ii[j]] != xx[i_] ? xx[ii[j]] - xx[i_] : (i_ & 1) - (ii[j] & 1); 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 iq[N + 1], pq[N], cnt; int lt(int i, int j) { return xx[i << 1 | 1] > xx[j << 1 | 1]; } int p2(int p) { return (p *= 2) > cnt ? 0 : (p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p); } void pq_up(int i) { int p, q, j; for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q) iq[pq[j] = p] = j; iq[pq[i] = p] = i; } void pq_dn(int i) { int p, q, j; for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q) iq[pq[j] = p] = j; iq[pq[i] = p] = i; } void pq_add(int i) { pq[i] = ++cnt, pq_up(i); } void pq_remove(int i) { int j = iq[cnt--]; if (j != i) pq[j] = pq[i], pq_up(j), pq_dn(j); pq[i] = 0; } int pq_first() { return iq[1]; } int main() { static int ii[N * 2]; int n, m, h, i, i_, c, c_, ans; scanf("%*d%d%d", &m, &n); ans = 0; for (i = 0; i < n; i++) { scanf("%d%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1], &cc[i]); ans += cc[i]; } for (i = 0; i < n * 2; i++) ii[i] = i; sort(ii, 0, n * 2); c = 0; for (h = 0; h < n * 2; h++) { i_ = ii[h], i = i_ >> 1; if ((i_ & 1) == 0) { pq_add(i), c += cc[i]; while (cnt && c > m) { i = pq_first(), c_ = min(c - m, cc[i]); if ((cc[i] -= c_) == 0) pq_remove(i); c -= c_, ans -= c_; } } else if (pq[i]) pq_remove(i), c -= cc[i]; } printf("%d\n", ans); return 0; }

Compilation message (stderr)

delivery.c: In function 'main':
delivery.c:81:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |  scanf("%*d%d%d", &m, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~
delivery.c:84:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |   scanf("%d%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1], &cc[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...