This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// name = molecules_c.c, type = c.gcc
#include "molecules_c.h"
// #include "molecules_c.h"
#include <stdlib.h>
int *w;
int comp(void const *x, void const *y) {
return w[*(int*)x] - w[*(int*)y];
}
int id[5234567];
int find_subset(int l, int u, int *w_, int n, int *res) {
w = w_;
for (int i = 0; i < n; i++) id[i] = i;
qsort(id, n, sizeof(int), comp);
int i = 0;
long long sum = 0;
while (i < n && sum + w[id[i]] <= u) {
sum += w[id[i++]];
}
if (sum >= l) {
for (int j = 0; j < i; j++) res[j] = id[j];
return i;
} else {
int j = 0;
while (i + j < n && sum < l) {
sum += w[id[i + j]] - w[id[j]];
j++;
}
if (sum < l) {
return 0;
} else {
for (int t = 0; t < i; t++) {
res[t] = id[t + j];
}
return 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |