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>
#include <stdlib.h>
#define N (1<<20)
int n, k, r_[N], u_[N], *r[N], *u[N], focus_topic, oc_[N], *oc[N], c[N], ii[N], z;
long long a[N];
int cmpr(const void *i, const void *j) {
return r[*(const int*)i][focus_topic] - r[*(const int*)j][focus_topic];
}
void check(int topic) {
while (ii[topic] < n && r[oc[topic][ii[topic]]][topic] <= a[topic]) {
if (k == ++c[oc[topic][ii[topic]]]) {
++z;
for (int jj = 0; jj < k; ++jj)
a[jj] += u[oc[topic][ii[topic]]][jj];
}
++ii[topic];
}
}
int main() {
scanf("%d%d", &n, &k);
for (int j = 0, i = 0; i < n; ++i, j += k) r[i] = r_ + j, u[i] = u_ + j;
for (int i = 0; i < n * k; ++i) scanf("%d", r_ + i);
for (int i = 0; i < n * k; ++i) scanf("%d", u_ + i);
for (int i = 0, j = 0; i < k; ++i, j += n) {
oc[i] = oc_ + j;
for (int l = 0; l < n; ++l)
oc[i][l] = l;
focus_topic = i;
qsort(oc[i], n, sizeof **oc, cmpr);
}
for (int j = 0; j <= n * 2; ++j)
for (int i = 0; i < k; ++i)
check(i);
printf("%d", z);
}
Compilation message (stderr)
Main.c: In function 'main':
Main.c:25:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:28:34: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | for (int i = 0; i < n * k; ++i) scanf("%d", r_ + i);
| ^~~~~~~~~~~~~~~~~~~
Main.c:29:34: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | for (int i = 0; i < n * k; ++i) scanf("%d", u_ + 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... |