Submission #544776

#TimeUsernameProblemLanguageResultExecution timeMemory
544776rainboyBodyguards (CEOI10_bodyguards)C11
100 / 100
175 ms11104 KiB
#include <stdio.h> #define N 200000 #define M 200000 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int *xx; 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 (xx[ii[j]] == xx[i_]) j++; else if (xx[ii[j]] < xx[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; } } int main() { static int aa[N], kk[N], bb[M], ll[M], ii[N], jj[M]; int n, m, i, j; long long a, k, b, l, sum; scanf("%d", &n); k = 0, sum = 0; for (i = 0; i < n; i++) { scanf("%d%d", &aa[i], &kk[i]); k += kk[i], sum += (long long) aa[i] * kk[i]; ii[i] = i; } xx = aa, sort(ii, 0, n); scanf("%d", &m); b = 0; for (j = 0; j < m; j++) { scanf("%d%d", &bb[j], &ll[j]); b += (long long) bb[j] * ll[j]; jj[j] = j; } xx = bb, sort(jj, 0, m); a = 0, l = 0, j = m - 1; while (j >= 0 && bb[jj[j]] >= k) { b -= (long long) bb[jj[j]] * ll[jj[j]], l += ll[jj[j]]; j--; } if (a + b < sum && k <= (sum - 1 - a - b) / l) { printf("0\n"); return 0; } for (i = 0; i < n; i++) { a += (long long) aa[ii[i]] * kk[ii[i]], k -= kk[ii[i]]; while (j >= 0 && bb[jj[j]] >= k) { b -= (long long) bb[jj[j]] * ll[jj[j]], l += ll[jj[j]]; j--; } if (a + b < sum && k <= (sum - 1 - a - b) / l) { printf("0\n"); return 0; } } printf("1\n"); return 0; }

Compilation message (stderr)

bodyguards.c: In function 'main':
bodyguards.c:38:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
bodyguards.c:41:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d%d", &aa[i], &kk[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bodyguards.c:46:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d", &m);
      |  ^~~~~~~~~~~~~~~
bodyguards.c:49:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d%d", &bb[j], &ll[j]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#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...