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 N 100000
double min(double a, double b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(double *aa, int l, int r) {
while (l < r) {
int i = l, j = l, k = r;
double a = aa[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[j] == a)
j++;
else if (aa[j] > a) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
i++, j++;
} else {
k--;
tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
}
sort(aa, l, i);
l = k;
}
}
int main() {
static double aa[N], bb[N];
int n, i, j;
double sum1, sum2, ans;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%lf%lf", &aa[i], &bb[i]);
sort(aa, 0, n);
sort(bb, 0, n);
sum1 = sum2 = 0, ans = 0, i = 0, j = 0;
while (i < n || j < n) {
if (i < n && (j == n || sum1 <= sum2))
sum1 += aa[i++];
else
sum2 += bb[j++];
ans = max(ans, min(sum1, sum2) - i - j);
}
printf("%.4f\n", ans);
return 0;
}
Compilation message (stderr)
sure.c: In function 'main':
sure.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
sure.c:41:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%lf%lf", &aa[i], &bb[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... |